From 3e2c7ffa4e550c61b259f84212a00c09616683d1 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 28 Oct 2025 10:03:09 -0400 Subject: [PATCH] rewrite pool subsecond test to use mocking the timing here is too sensitive to play out reliably on CI machines particularly free threaded, so mock the time() callable instead and ensure with subsecond clock intervals we do the right math Change-Id: Icc203ae2298eb4b64e3b45f063811e9527278d0c (cherry picked from commit 4147accbd2b70493c01df18fd0d4598c4e1cb72e) --- test/engine/test_pool.py | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/test/engine/test_pool.py b/test/engine/test_pool.py index e876c0419c..f7016a02e7 100644 --- a/test/engine/test_pool.py +++ b/test/engine/test_pool.py @@ -1083,16 +1083,32 @@ class QueuePoolTest(PoolTestBase): assert_raises(tsa.exc.TimeoutError, p.connect) assert int(time.time() - now) == 2 - @testing.requires.timing_intensive def test_timeout_subsecond_precision(self): - p = self._queuepool_fixture(pool_size=1, max_overflow=0, timeout=0.5) - c1 = p.connect() # noqa - with expect_raises(tsa.exc.TimeoutError): - now = time.time() - c2 = p.connect() # noqa - # Python timing is not very accurate, the time diff should be very - # close to 0.5s but we give 200ms of slack. - assert 0.3 <= time.time() - now <= 0.7, "Pool timeout not respected" + """test that a subsecond precision is passed to queue.get() + and that the math comparison is float sensitive + + """ + times = [ + # will set endtime at 1761659753.1250672 + .5 + 1761659753.1250672, + # will be within the timeout + 1761659753.349, + # will be outside the timeout, should raise Empty + # if the timeout is a whole number, then this would not be + # enough time to wait and we get "pop from an empty list" + 1761659753.715, + ] + + def mock_time(): + return times.pop(0) + + with mock.patch("sqlalchemy.util.queue._time", mock_time): + p = self._queuepool_fixture( + pool_size=1, max_overflow=0, timeout=0.5 + ) + c1 = p.connect() # noqa + with expect_raises(tsa.exc.TimeoutError): + p.connect() @testing.requires.threading_with_mock @testing.requires.timing_intensive -- 2.47.3