From 087a96d22e2b8d5e4506acc1f3c605abf4f978cd Mon Sep 17 00:00:00 2001 From: Tamo Date: Wed, 27 Mar 2024 11:05:37 +0100 Subject: [PATCH] fix flaky test --- meilisearch/src/search_queue.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/meilisearch/src/search_queue.rs b/meilisearch/src/search_queue.rs index b661fefb0..ad222cdf8 100644 --- a/meilisearch/src/search_queue.rs +++ b/meilisearch/src/search_queue.rs @@ -47,6 +47,18 @@ impl SearchQueue { loop { tokio::select! { + // biased select because we wants to free up space before trying to register new tasks + biased; + _ = search_finished.recv() => { + searches_running = searches_running.saturating_sub(1); + if !queue.is_empty() { + // Can't panic: the queue wasn't empty thus the range isn't empty. + let remove = rng.gen_range(0..queue.len()); + let channel = queue.swap_remove(remove); + let _ = channel.send(Permit { sender: sender.clone() }); + } + }, + search_request = receive_new_searches.recv() => { // this unwrap is safe because we're sure the `SearchQueue` still lives somewhere in actix-web let search_request = search_request.unwrap(); @@ -69,15 +81,6 @@ impl SearchQueue { } queue.push(search_request); }, - _ = search_finished.recv() => { - searches_running = searches_running.saturating_sub(1); - if !queue.is_empty() { - // Can't panic: the queue wasn't empty thus the range isn't empty. - let remove = rng.gen_range(0..queue.len()); - let channel = queue.swap_remove(remove); - let _ = channel.send(Permit { sender: sender.clone() }); - } - }, } } }