-
Notifications
You must be signed in to change notification settings - Fork 24
Description
Description
We have tons of tests inside tap-agent and indexer-common that uses sleep to propagate messages and other stuff. @suchapalaver suggested that we should have a way to wait for a specific update with a timeout. This could be really useful for our actor system that needs to wait for some messages to be propagated and currently we have some non-determinism inside tests because it takes more than the current sleep time.
A second approach is to use channels to wait for messages like we do here:
| let last_message_emitted = last_message_emitted.recv().await.unwrap(); |
In any way we should rely less on sleeps with arbitrary values and more in waiting messages and reliable waiting where we do some sleeps for a few times until we got the correct output or fail with a timeout.
PR Comment
The sleep makes things a bit confusing.
You could use something like this:
async fn wait_for_update(check: &MinimumValue) {
tokio::time::timeout(Duration::from_secs(1), async {
while check.cost_model_map.read().unwrap().len() != expected_len {
sleep(Duration::from_millis(50)).await;
}
}).await.unwrap();
}I think the intention is clearer.
Originally posted by @suchapalaver in #153 (comment)