From cf7aad66440f3143032ffe054bb1598732bff3c4 Mon Sep 17 00:00:00 2001 From: Thomas Kpenou Date: Thu, 28 May 2026 12:22:03 -0400 Subject: [PATCH] fix: prevent flaky test_time_buffer_aggregated_read_until_closed on Python 3.10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test used time_buffered(100ms) while _test_read_until_closed sends late messages after a 100ms sleep. Both timers expire simultaneously, creating a race: the flush thread can process the late messages and close the buffered observable before read_until_closed subscribes (at t≈140ms), producing data=[]. Switch to 30ms so flush cycles land at t=30/60/90/120ms; the subscription is established at t≈49ms and the late-message flush happens at t≈120ms, after the subscriber is in place. Co-Authored-By: Claude Sonnet 4.6 --- src/tests/observable_test.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/tests/observable_test.py b/src/tests/observable_test.py index 3c5a8897..9f1a5367 100644 --- a/src/tests/observable_test.py +++ b/src/tests/observable_test.py @@ -745,7 +745,14 @@ def test_time_buffer_read_until_closed(self): def test_time_buffer_aggregated_read_until_closed(self): observable = self.create_observable() - buffered_observable = observable.time_buffered(100, lambda chunks: ['|'.join(chunks)]) + # Use 30ms period (not 100ms) to avoid a timing race: the helper + # _test_read_until_closed sends late messages after 100ms sleep. + # With period=100ms both the flush thread and the async thread fire at + # ~t=100ms; the flush thread can close the buffered observable before + # read_until_closed subscribes (at t≈140ms), resulting in empty data. + # With period=30ms flush cycles land at t=30/60/90/120ms; the subscriber + # is set up at t≈49ms and the late-message flush happens at t≈120ms. + buffered_observable = observable.time_buffered(30, lambda chunks: ['|'.join(chunks)]) data, _, late_messages = self._test_read_until_closed( observable,