Skip to content

Commit

Permalink
add test for refguard ref counting
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Mar 1, 2024
1 parent 1c5265e commit 2707b12
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/test_coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::{task::Poll, thread, time::Duration};

use futures::{channel::oneshot, future::poll_fn, FutureExt};
use portable_atomic::{AtomicBool, Ordering};
use pyo3::{
coroutine::CancelHandle,
prelude::*,
Expand Down Expand Up @@ -259,6 +260,15 @@ fn test_async_method_receiver() {
self.0
}
}

static IS_DROPPED: AtomicBool = AtomicBool::new(false);

impl Drop for Counter {
fn drop(&mut self) {
IS_DROPPED.store(true, Ordering::SeqCst);
}
}

Python::with_gil(|gil| {
let test = r#"
import asyncio
Expand Down Expand Up @@ -291,5 +301,7 @@ fn test_async_method_receiver() {
"#;
let locals = [("Counter", gil.get_type_bound::<Counter>())].into_py_dict_bound(gil);
py_run!(gil, *locals, test);
})
});

assert!(IS_DROPPED.load(Ordering::SeqCst));
}

0 comments on commit 2707b12

Please sign in to comment.