From 6643fc2e5608fe8adaaaa13bb98510ef297fd302 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Wed, 4 Nov 2026 15:06:37 -0800 Subject: [PATCH] test(least-busy): wait for the helper thread to start before the timed join --- tests/unit/router_strategy/test_least_busy.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/unit/router_strategy/test_least_busy.py b/tests/unit/router_strategy/test_least_busy.py index 361d876fb46..5b13d21af53 100644 --- a/tests/unit/router_strategy/test_least_busy.py +++ b/tests/unit/router_strategy/test_least_busy.py @@ -616,7 +616,7 @@ def test_a_reservation_and_a_release_on_one_deployment_at_once_both_count() -> N class _SlowLocalRead(InMemoryCache): - """Answers a count read with the counts from when the read started, after giving another thread a moment to run.""" + """Answers a count read with the counts from when the read started, once another thread has begun its request.""" def __init__(self) -> None: super().__init__() @@ -625,8 +625,15 @@ class _SlowLocalRead(InMemoryCache): def batch_get_cache(self, keys: list[str], **kwargs: object) -> list[object]: counts_when_asked: Final = super().batch_get_cache(keys, **kwargs) - self.other_thread = threading.Thread(target=self.while_reading) + began: Final = threading.Event() + + def begin_then_run() -> None: + began.set() + self.while_reading() + + self.other_thread = threading.Thread(target=begin_then_run) self.other_thread.start() + began.wait() self.other_thread.join(timeout=0.2) return counts_when_asked