From 53312c12ad7f5b41c6ffd5da453efaf760af97eb Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Fri, 1 Mar 2024 12:11:55 +0000 Subject: [PATCH] add test for refguard ref counting --- tests/test_coroutine.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/test_coroutine.rs b/tests/test_coroutine.rs index e04aafda24d..db79c72a233 100644 --- a/tests/test_coroutine.rs +++ b/tests/test_coroutine.rs @@ -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::*, @@ -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 @@ -291,5 +301,7 @@ fn test_async_method_receiver() { "#; let locals = [("Counter", gil.get_type_bound::())].into_py_dict_bound(gil); py_run!(gil, *locals, test); - }) + }); + + assert!(IS_DROPPED.load(Ordering::SeqCst)); }