Skip to content

Commit 98aac61

Browse files
author
Stjepan Glavina
committed
More tests
1 parent 4079184 commit 98aac61

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

tests/drop.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
44
use std::sync::Mutex;
55
use std::task::{Poll, Waker};
66

7-
use async_executor::{Task,Executor};
7+
use async_executor::{Executor, Task};
88
use futures_lite::future;
99
use once_cell::sync::Lazy;
1010

@@ -81,6 +81,44 @@ fn await_task_after_dropping_executor() {
8181
drop(s);
8282
}
8383

84+
#[test]
85+
fn drop_executor_and_then_drop_finished_task() {
86+
static DROP: AtomicUsize = AtomicUsize::new(0);
87+
88+
let ex = Executor::new();
89+
let task = ex.spawn(async {
90+
CallOnDrop(|| {
91+
DROP.fetch_add(1, Ordering::SeqCst);
92+
})
93+
});
94+
assert!(ex.try_tick());
95+
96+
assert_eq!(DROP.load(Ordering::SeqCst), 0);
97+
drop(ex);
98+
assert_eq!(DROP.load(Ordering::SeqCst), 0);
99+
drop(task);
100+
assert_eq!(DROP.load(Ordering::SeqCst), 1);
101+
}
102+
103+
#[test]
104+
fn drop_finished_task_and_then_drop_executor() {
105+
static DROP: AtomicUsize = AtomicUsize::new(0);
106+
107+
let ex = Executor::new();
108+
let task = ex.spawn(async {
109+
CallOnDrop(|| {
110+
DROP.fetch_add(1, Ordering::SeqCst);
111+
})
112+
});
113+
assert!(ex.try_tick());
114+
115+
assert_eq!(DROP.load(Ordering::SeqCst), 0);
116+
drop(task);
117+
assert_eq!(DROP.load(Ordering::SeqCst), 1);
118+
drop(ex);
119+
assert_eq!(DROP.load(Ordering::SeqCst), 1);
120+
}
121+
84122
struct CallOnDrop<F: Fn()>(F);
85123

86124
impl<F: Fn()> Drop for CallOnDrop<F> {

0 commit comments

Comments
 (0)