A repeating pattern in the functional tests is that the test sleeps for a while to ensure that a certain condition is still true after some amount of time has elapsed. Most recently a new case of this was added in #30807. This PR here introduces an ensure
helper to streamline this functionality.
Some approach considerations:
- It is possible to construct this by reusing
wait_until
and wrapping it intry
internally. However, the logger output of the failing wait would still be printed which seems irritating. So I opted for simplified but similar internals towait_until
. - This implementation starts for a failure in the condition right away which has the nice side-effect that it might give feedback on a failure earlier than is currently the case. However, in some cases, it may be expected that the condition may still be false at the beginning and then turns true until time has run out, something that would work when the test sleeps without checking in a loop. I decided against this design (and even against adding it as an option) because such a test design seems like it would be racy either way.
- I have also been going back and forth on naming. To me
ensure
works well but I am also not a native speaker, happy consider a different name if others don’t think it’s clear enough.