From 673b6e1dc0f9ad6d688c5f8da7295d1f4e041c5f Mon Sep 17 00:00:00 2001 From: Tamo Date: Thu, 16 May 2024 11:28:14 +0200 Subject: [PATCH] fix a flaky test --- meilisearch/tests/snapshot/mod.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/meilisearch/tests/snapshot/mod.rs b/meilisearch/tests/snapshot/mod.rs index 1312aa9ca..67e80f45b 100644 --- a/meilisearch/tests/snapshot/mod.rs +++ b/meilisearch/tests/snapshot/mod.rs @@ -1,6 +1,5 @@ use std::time::Duration; -use actix_rt::time::sleep; use meili_snap::{json_string, snapshot}; use meilisearch::option::ScheduleSnapshot; use meilisearch::Opt; @@ -53,11 +52,29 @@ async fn perform_snapshot() { index.load_test_set().await; - server.index("test1").create(Some("prim")).await; + let (task, code) = server.index("test1").create(Some("prim")).await; + meili_snap::snapshot!(code, @"202 Accepted"); - index.wait_task(2).await; + index.wait_task(task.uid()).await; - sleep(Duration::from_secs(2)).await; + // wait for the _next task_ to process, aka the snapshot that should be enqueued at some point + + println!("waited for the next task to finish"); + let now = std::time::Instant::now(); + let next_task = task.uid() + 1; + loop { + let (value, code) = index.get_task(next_task).await; + dbg!(&value); + if code != 404 && value["status"].as_str() == Some("succeeded") { + break; + } + + if now.elapsed() > Duration::from_secs(30) { + panic!("The snapshot didn't schedule in 30s even though it was supposed to be scheduled every 2s: {}", + serde_json::to_string_pretty(&value).unwrap() + ); + } + } let temp = tempfile::tempdir().unwrap();