mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-21 00:00:10 +02:00
Test some more mpsc behavior with loom (#2246)
This commit is contained in:
@@ -21,3 +21,57 @@ fn closing_tx() {
|
||||
assert!(v.is_none());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn closing_unbounded_tx() {
|
||||
loom::model(|| {
|
||||
let (tx, mut rx) = mpsc::unbounded_channel();
|
||||
|
||||
thread::spawn(move || {
|
||||
tx.send(()).unwrap();
|
||||
drop(tx);
|
||||
});
|
||||
|
||||
let v = block_on(poll_fn(|cx| rx.poll_recv(cx)));
|
||||
assert!(v.is_some());
|
||||
|
||||
let v = block_on(poll_fn(|cx| rx.poll_recv(cx)));
|
||||
assert!(v.is_none());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dropping_tx() {
|
||||
loom::model(|| {
|
||||
let (tx, mut rx) = mpsc::channel::<()>(16);
|
||||
|
||||
for _ in 0..2 {
|
||||
let tx = tx.clone();
|
||||
thread::spawn(move || {
|
||||
drop(tx);
|
||||
});
|
||||
}
|
||||
drop(tx);
|
||||
|
||||
let v = block_on(poll_fn(|cx| rx.poll_recv(cx)));
|
||||
assert!(v.is_none());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dropping_unbounded_tx() {
|
||||
loom::model(|| {
|
||||
let (tx, mut rx) = mpsc::unbounded_channel::<()>();
|
||||
|
||||
for _ in 0..2 {
|
||||
let tx = tx.clone();
|
||||
thread::spawn(move || {
|
||||
drop(tx);
|
||||
});
|
||||
}
|
||||
drop(tx);
|
||||
|
||||
let v = block_on(poll_fn(|cx| rx.poll_recv(cx)));
|
||||
assert!(v.is_none());
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user