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

fix flaky tests on free-threaded build #4576

Merged
merged 2 commits into from
Sep 26, 2024
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
14 changes: 11 additions & 3 deletions tests/test_gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ fn class_with_freelist() {
});
}

/// Tests that drop is eventually called on objects that are dropped when the
/// GIL is not held.
///
/// On the free-threaded build, threads are resumed before tp_clear() calls
/// finish. Therefore, if the type needs __traverse__, drop might not necessarily
/// be called by the time the a test re-acquires a Python thread state and checks if
/// drop has been called.
///
/// See https://peps.python.org/pep-0703/#stop-the-world
struct TestDropCall {
drop_called: Arc<AtomicBool>,
}
Expand Down Expand Up @@ -120,9 +129,6 @@ fn gc_integration() {
Python::with_gil(|py| {
py.run(ffi::c_str!("import gc; gc.collect()"), None, None)
.unwrap();
// threads are resumed before tp_clear() calls finish, so drop might not
// necessarily be called when we get here see
// https://peps.python.org/pep-0703/#stop-the-world
#[cfg(not(Py_GIL_DISABLED))]
assert!(drop_called.load(Ordering::Relaxed));
});
Expand Down Expand Up @@ -482,6 +488,7 @@ fn drop_during_traversal_with_gil() {
.unwrap();
});
}
#[cfg(not(Py_GIL_DISABLED))]
assert!(drop_called.load(Ordering::Relaxed));
}

Expand Down Expand Up @@ -517,6 +524,7 @@ fn drop_during_traversal_without_gil() {
.unwrap();
});
}
#[cfg(not(Py_GIL_DISABLED))]
assert!(drop_called.load(Ordering::Relaxed));
}

Expand Down
Loading