The test suite I have to test my email sending and querying with an email API provider returns 429 too many requests when I run them one after the other in a short amount of time. Even when I run the tests with cargo test -- --test-threads = 1 to keep the requests synchronous.

Ideally I would wait something like 5 seconds before running some of the tests.

So I checked the book chapter Controlling How Tests Are Run but there's no option there and also Cargo Book Test section, but couldn't find what I'm looking for.

Using a mock server to test emails is not an option I consider.

Should I put a tokio::time::sleep(Duration).await to the beginning of every such test or is there a testing library or feature I can use for this and maybe similar other custom test scenarios?

4 posts - 3 participants

Read full topic