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

gh-111119: Fix flaky test test_lock_two_threads #111124

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Modules/_testinternalcapi/test_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,18 @@ test_lock_two_threads(PyObject *self, PyObject *obj)
assert(test_data.m.v == 1);

PyThread_start_new_thread(lock_thread, &test_data);
while (!_Py_atomic_load_int(&test_data.started)) {
pysleep(10);
}
pysleep(10); // allow some time for the other thread to try to lock

// wait up to two seconds for the lock_thread to attempt to lock "m"
int iters = 0;
uint8_t v;
do {
pysleep(10); // allow some time for the other thread to try to lock
v = _Py_atomic_load_uint8_relaxed(&test_data.m.v);
assert(v == 1 || v == 3);
iters++;
} while (v != 3 && iters < 200);

// both the "locked" and the "has parked" bits should be set
assert(test_data.m.v == 3);

PyMutex_Unlock(&test_data.m);
Expand Down
Loading