From c6f25e42a285c22a29c82b8da1ff8d365f9db632 Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Fri, 29 Mar 2024 15:51:38 +0000 Subject: [PATCH] ci: relax check in pyobject_drop test (#4014) --- src/gil.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/gil.rs b/src/gil.rs index bb07489fa1f..e2f36037755 100644 --- a/src/gil.rs +++ b/src/gil.rs @@ -556,11 +556,11 @@ mod tests { } #[cfg(not(target_arch = "wasm32"))] - fn pool_dirty_with( - inc_refs: Vec>, - dec_refs: Vec>, - ) -> bool { - *POOL.pointer_ops.lock() == (inc_refs, dec_refs) + fn pool_dec_refs_contains(obj: &PyObject) -> bool { + POOL.pointer_ops + .lock() + .1 + .contains(&unsafe { NonNull::new_unchecked(obj.as_ptr()) }) } #[test] @@ -633,11 +633,13 @@ mod tests { assert_eq!(obj.get_refcnt(py), 2); assert!(pool_inc_refs_does_not_contain(&obj)); + assert!(pool_dec_refs_does_not_contain(&obj)); - // With the GIL held, reference cound will be decreased immediately. + // With the GIL held, reference count will be decreased immediately. drop(reference); assert_eq!(obj.get_refcnt(py), 1); + assert!(pool_inc_refs_does_not_contain(&obj)); assert!(pool_dec_refs_does_not_contain(&obj)); }); } @@ -652,6 +654,7 @@ mod tests { assert_eq!(obj.get_refcnt(py), 2); assert!(pool_inc_refs_does_not_contain(&obj)); + assert!(pool_dec_refs_does_not_contain(&obj)); // Drop reference in a separate thread which doesn't have the GIL. std::thread::spawn(move || drop(reference)).join().unwrap(); @@ -659,10 +662,8 @@ mod tests { // The reference count should not have changed (the GIL has always // been held by this thread), it is remembered to release later. assert_eq!(obj.get_refcnt(py), 2); - assert!(pool_dirty_with( - vec![], - vec![NonNull::new(obj.as_ptr()).unwrap()] - )); + assert!(pool_inc_refs_does_not_contain(&obj)); + assert!(pool_dec_refs_contains(&obj)); obj });