Remove sleeps from tests
Replace sleeps with the existing polling function instead. Exposes that the stress test isn't much of a stress test, it probably needs more data or something, but if it's heavy it should maybe not be part of `just test`
34 unmodified lines3536373839403940414243444546474849505152535455565758734 unmodified linesExpand all79379479579678378479779834 unmodified lines let (cache_b, rl_b, _addr_b) = RippleEngine::start(config_b, shutdown.clone()) .await .expect("node B failed to start");
tokio::time::sleep(Duration::from_millis(2000)).await;
cache_a .set("__ready_a", "1", Duration::from_secs(60)) .await .expect("readiness probe on A failed"); cache_b .set("__ready_b", "1", Duration::from_secs(60)) .await .expect("readiness probe on B failed"); poll_until(10_000, 50, || { let cache_a = cache_a.clone(); let cache_b = cache_b.clone(); async move { cache_b.get("__ready_a").await.is_some() && cache_a.get("__ready_b").await.is_some() } }) .await; ((cache_a, rl_a), (cache_b, rl_b))}
async fn poll_until<F, Fut>(max_ms: u64, interval_ms: u64, check_fn: F)734 unmodified linesExpand all results.into_iter().enumerate().for_each(|(i, r)| { r.unwrap_or_else(|e| panic!("task {i} panicked: {e}")); });
tokio::time::sleep(Duration::from_secs(12)).await;
shutdown.cancel();}745 unmodified linesExpand all746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781750782783784785786787473 unmodified linesExpand all745 unmodified linesExpand all
let first = &instances[0]; APP_PORT.set(first.port).ok();
let caches: Vec<Arc<dyn Cache>> = instances .iter() .map(|instance| instance.cache.clone().expect("cluster node has no cache")) .collect(); futures::future::join_all(caches.iter().enumerate().map(|(i, cache)| async move { cache .set( &format!("__cluster_ready_{i}"), "1", Duration::from_secs(60), ) .await .expect("cluster readiness probe failed"); })) .await; let deadline = tokio::time::Instant::now() + Duration::from_secs(10); loop { let ready = futures::future::join_all(caches.iter().flat_map(|cache| { (0..caches.len()).map(move |i| async move { cache.get(&format!("__cluster_ready_{i}")).await.is_some() }) })) .await .into_iter() .all(|seen| seen); if ready { break; } assert!( tokio::time::Instant::now() < deadline, "cluster nodes did not converge within 10s" ); tokio::time::sleep(Duration::from_millis(2000)).await; tokio::time::sleep(Duration::from_millis(50)).await; }
instances}
473 unmodified linesExpand all