From 7a5a38f870297970449dae376e26b692da1a59ab Mon Sep 17 00:00:00 2001 From: Tamo Date: Tue, 30 Jul 2024 15:09:12 +0200 Subject: [PATCH] fix a sync issue on empty indexes --- meilisearch/tests/common/mod.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/meilisearch/tests/common/mod.rs b/meilisearch/tests/common/mod.rs index 9a594f8f1..afbd5a2f5 100644 --- a/meilisearch/tests/common/mod.rs +++ b/meilisearch/tests/common/mod.rs @@ -149,17 +149,17 @@ pub async fn shared_does_not_exists_index() -> &'static Index<'static, Shared> { } pub async fn shared_empty_index() -> &'static Index<'static, Shared> { - static INDEX: Lazy> = Lazy::new(|| { - let server = Server::new_shared(); - server._index("EMPTY_INDEX").to_shared() - }); - let index = Lazy::get(&INDEX); - // That means the lazy has never been initialized, we need to create the index and index the documents - if index.is_none() { - let (response, _code) = INDEX._create(None).await; - INDEX.wait_task(response.uid()).await.succeeded(); - } - &INDEX + static INDEX: OnceCell> = OnceCell::const_new(); + + INDEX + .get_or_init(|| async { + let server = Server::new_shared(); + let index = server._index("EMPTY_INDEX").to_shared(); + let (response, _code) = index._create(None).await; + index.wait_task(response.uid()).await.succeeded(); + index + }) + .await } pub static DOCUMENTS: Lazy = Lazy::new(|| {