-
-
Notifications
You must be signed in to change notification settings - Fork 37.1k
gh-158336: Fix race in lock_tests test_set_and_clear #158337
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -572,8 +572,13 @@ def f(): | |
|
|
||
| N = 5 | ||
| with Bunch(f, N): | ||
| # Threads blocked on event.wait() | ||
| wait_threads_blocked(N) | ||
| # Wait until all threads are registered as waiters in | ||
| # event.wait(). A thread that only reaches wait() after set() | ||
| # and clear() would block until the timeout, so a fixed sleep | ||
| # is not enough on a busy machine. | ||
| for _ in support.sleeping_retry(support.SHORT_TIMEOUT): | ||
| if len(event._cond._waiters) >= N: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If possible, I would prefer to avoid accessing private attributes. Can you try instead to test
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, test might be something like below: def test_set_and_clear(self):
# gh-57711: check that wait() returns true even when the event is
# cleared before the waiting thread is woken up.
event = self.eventtype()
N = 5
ready = []
results = []
def f():
ready.append(True)
results.append(event.wait(support.LONG_TIMEOUT))
with Bunch(f, N):
# Threads blocked on event.wait()
for _ in support.sleeping_retry(support.SHORT_TIMEOUT):
if len(ready) >= N:
break
# Threads unblocked
event.set()
for _ in support.sleeping_retry(support.SHORT_TIMEOUT):
if len(results) >= N:
break
event.clear()
self.assertEqual(results, [True] * N)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The test description says:
Waiting for theads between set() and clear() seems to go against the test description.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. The |
||
| break | ||
|
|
||
| # Threads unblocked | ||
| event.set() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that the second part of the comment is useful.