Skip to content

Commit

Permalink
ci: relax check in pyobject_drop test (#4014)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt authored Mar 29, 2024
1 parent ae3ac7d commit c6f25e4
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/gil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,11 +556,11 @@ mod tests {
}

#[cfg(not(target_arch = "wasm32"))]
fn pool_dirty_with(
inc_refs: Vec<NonNull<ffi::PyObject>>,
dec_refs: Vec<NonNull<ffi::PyObject>>,
) -> 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]
Expand Down Expand Up @@ -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));
});
}
Expand All @@ -652,17 +654,16 @@ 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();

// 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
});

Expand Down

0 comments on commit c6f25e4

Please sign in to comment.