{"id":23816774,"url":"https://github.com/dfaust/repeated-assert","last_synced_at":"2025-02-21T20:44:06.386Z","repository":{"id":57660097,"uuid":"86098167","full_name":"dfaust/repeated-assert","owner":"dfaust","description":"An assertion macro that tries to assert expressions multiple times","archived":false,"fork":false,"pushed_at":"2023-12-16T10:43:35.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-03T21:02:41.648Z","etag":null,"topics":["helper","integration-testing","rust"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dfaust.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-24T18:17:59.000Z","updated_at":"2023-12-16T10:43:39.000Z","dependencies_parsed_at":"2022-09-06T23:20:35.425Z","dependency_job_id":null,"html_url":"https://github.com/dfaust/repeated-assert","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfaust%2Frepeated-assert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfaust%2Frepeated-assert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfaust%2Frepeated-assert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfaust%2Frepeated-assert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dfaust","download_url":"https://codeload.github.com/dfaust/repeated-assert/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240086455,"owners_count":19745822,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["helper","integration-testing","rust"],"created_at":"2025-01-02T04:32:17.266Z","updated_at":"2025-02-21T20:44:06.366Z","avatar_url":"https://github.com/dfaust.png","language":"Rust","readme":"# repeated-assert\n\n[![Crate version](https://img.shields.io/crates/d/repeated-assert)](https://crates.io/crates/repeated-assert)\n[![Documentation](https://img.shields.io/docsrs/repeated-assert)](https://docs.rs/repeated-assert)\n\nRun assertions multiple times\n\n`repeated_assert` runs assertions until they either pass\nor the maximum amount of repetitions has been reached.\nThe current thread will be blocked between tries.\n\nThis is useful when waiting for events from another thread (or process).\nWaiting for a short time might result in a failing test, while waiting too long is a waste of time.\n\n## Crate features\n\n* **async** - Enables the `that_async` and `with_catch_async` functions. It depends on the `futures` and `tokio` crates, which is why it's disabled by default.\n\n## Examples\n\nWaiting for a file to appear (re-try up to 10 times, wait 50 ms between tries)\n\n```rust,ignore\nrepeated_assert::that(10, Duration::from_millis(50), || {\n    assert!(Path::new(\"should_appear_soon.txt\").exists());\n});\n```\n\nWaiting for variable `x` to equal `3`\n\n```rust,ignore\nrepeated_assert::that(10, Duration::from_millis(50), || {\n    assert_eq!(x, 3);\n});\n```\n\nTemporary variables\n\n```rust,ignore\nrepeated_assert::that(10, Duration::from_millis(50), || {\n    let checksum = crc(\"should_appear_soon.txt\");\n    assert_eq!(checksum, 1234);\n});\n```\n\nReturn result\n\n```rust,ignore\nrepeated_assert::that(10, Duration::from_millis(50), || -\u003e Result\u003c_, Box\u003cdyn std::error::Error\u003e\u003e {\n    let checksum = crc(\"should_appear_soon.txt\")?;\n    assert_eq!(checksum, 1234);\n})?;\n```\n\nAsync\n\n```rust,ignore\nrepeated_assert::that_async(10, Duration::from_millis(50), || async {\n    let status = query_db().await;\n    assert_eq!(status, \"success\");\n}).await;\n```\n\n## Catch failing tests\n\nIt's also possible to \"catch\" failing tests by executing some code if the expressions couldn't be asserted in order to trigger an alternate strategy.\nThis can be useful if the tested program relies on an unreliable service.\nThis counters the idea of a test to some degree, so use it only if the unreliable service is not critical for your program.\n\nPoke unreliable service after 5 unsuccessful assertion attempts\n\n```rust,ignore\nrepeated_assert::with_catch(10, Duration::from_millis(50), 5,\n    || {\n        // poke unreliable service\n    },\n    || {\n        assert!(Path::new(\"should_appear_soon.txt\").exists());\n    }\n);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdfaust%2Frepeated-assert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdfaust%2Frepeated-assert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdfaust%2Frepeated-assert/lists"}