Skip to content
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_multiprocessing_forkserver.test_processes.WithProcessesTestLock.test_repr_rlock is flaky #128206

Open
mpage opened this issue Dec 23, 2024 · 0 comments
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@mpage
Copy link
Contributor

mpage commented Dec 23, 2024

Bug report

Bug description:

The implementation of test_multiprocessing_forkserver.test_processes.WithProcessesTestLock.test_repr_rlock is racy; this leads to test failures on unrelated PRs:

The linked failures are a result of the raciness in the test:

t = threading.Thread(target=self._acquire_release,
args=(lock, 0.2),
name=f'T1')
t.start()
time.sleep(0.1)
self.assertEqual('<RLock(SomeOtherThread, nonzero)>', repr(lock))

and the function, _acquire_release, which runs in the thread:

@staticmethod
def _acquire_release(lock, timeout, l=None, n=1):
for _ in range(n):
lock.acquire()
if l is not None:
l.append(repr(lock))
time.sleep(timeout)
for _ in range(n):
lock.release()

The tests will fail if _acquire_release runs to completion or doesn't acquire the lock before the test checks the repr.

We should rewrite test_repr_rlock so that it does not use time.sleep() as a mechanism for ordering events between different processes/threads.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

@mpage mpage added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir labels Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant