New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test_logging: test_config_queue_handler() race condition #93761
Comments
I suggest to wait until the queue is empty instead ( diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 87b3efa406..da5c68e5d7 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -3609,13 +3609,17 @@ def do_queuehandler_configuration(self, qspec, lspec):
self.assertEqual(sorted(logging.getHandlerNames()), ['ah', 'h1'])
self.assertIsNotNone(qh.listener)
qh.listener.start()
- # Need to let the listener thread get started
- time.sleep(delay)
+
logging.debug('foo')
logging.info('bar')
logging.warning('baz')
- # Need to let the listener thread finish its work
- time.sleep(delay)
+
+ deadline = time.monotonic() + support.LONG_TIMEOUT
+ while not qh.listener.queue.empty():
+ time.sleep(0.010)
+ if time.monotonic() > deadline:
+ self.fail("queue not empty")
+
with open(fn, encoding='utf-8') as f:
data = f.read().splitlines()
self.assertEqual(data, ['foo', 'bar', 'baz']) |
@vstinner Thanks for raising this, Victor, and sorry for not thinking about the buildbots. I will rectify that soon! |
vsajip
added a commit
to vsajip/cpython
that referenced
this issue
Jun 13, 2022
The problem is more generic than buildbots. The test can fail randomly on any machine depending on the system load ;-)
Great! Thanks. |
vsajip
added a commit
that referenced
this issue
Jun 14, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The implementation of test_logging.test_config_queue_handler() uses time.sleep(0.010) as synchronization primitive.
@vsajip: please don't use time.sleep() as sync primitive: https://pythondev.readthedocs.io/unstable_tests.html#don-t-use-sleep-as-synchronization
The test fails when the machine is busy:
Extract of the test:
The text was updated successfully, but these errors were encountered: