|
2 | 2 | import pickle |
3 | 3 | import threading |
4 | 4 | from textwrap import dedent |
| 5 | +import time |
5 | 6 | import unittest |
6 | 7 | from unittest import mock |
7 | 8 |
|
@@ -356,26 +357,17 @@ def test_get_timeout(self): |
356 | 357 | queue.get(HUGE_TIMEOUT, 0.1) |
357 | 358 |
|
358 | 359 | def test_timeout_uses_monotonic_clock(self): |
359 | | - # gh-153005: the timeout deadline must be based on time.monotonic(), |
360 | | - # not the wall clock, so adjusting the system clock during the call |
361 | | - # cannot make get()/put() over- or under-wait. |
362 | | - class FakeClock: |
363 | | - def __init__(self): |
364 | | - self.now = 1000.0 |
365 | | - def monotonic(self): |
366 | | - return self.now |
367 | | - def sleep(self, delay): |
368 | | - self.now += delay |
369 | | - def time(self): |
370 | | - raise AssertionError('the wall clock must not be used') |
371 | | - |
372 | | - with mock.patch.object(queues, 'time', FakeClock()): |
373 | | - queue = queues.create(1) |
| 360 | + # gh-153005: the deadline must be computed from the monotonic clock, |
| 361 | + # since the wall clock can be adjusted while the call is blocked. |
| 362 | + queue = queues.create(1) |
| 363 | + with mock.patch.object(queues, 'time', wraps=time) as fake_time: |
374 | 364 | with self.assertRaises(queues.QueueEmpty): |
375 | | - queue.get(timeout=1, _delay=0.4) |
| 365 | + queue.get(timeout=0) |
376 | 366 | queue.put(None) |
377 | 367 | with self.assertRaises(queues.QueueFull): |
378 | | - queue.put(None, timeout=1, _delay=0.4) |
| 368 | + queue.put(None, timeout=0) |
| 369 | + fake_time.monotonic.assert_called() |
| 370 | + fake_time.time.assert_not_called() |
379 | 371 |
|
380 | 372 | def test_get_nowait(self): |
381 | 373 | queue = queues.create() |
|
0 commit comments