]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
rewrite pool subsecond test to use mocking
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 28 Oct 2025 14:03:09 +0000 (10:03 -0400)
committerMichael Bayer <mike_mp@zzzcomputing.com>
Tue, 28 Oct 2025 18:07:34 +0000 (18:07 +0000)
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

index e876c0419cc47e9582ad12736643d8f902618faa..f7016a02e7b55476180f921cd694b246162bd03e 100644 (file)
@@ -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