Test some more mpsc behavior with loom (#2246)

This commit is contained in:
Jon Gjengset
2020-02-14 12:03:57 -05:00
committed by GitHub
parent 466dd4a851
commit 564da5c128
+54
View File
@@ -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());
});
}