summaryrefslogtreecommitdiffstats
path: root/tokio/src/sync/tests
diff options
context:
space:
mode:
authorJon Gjengset <jon@thesquareplanet.com>2020-02-14 12:03:57 -0500
committerGitHub <noreply@github.com>2020-02-14 12:03:57 -0500
commit564da5c1289164d154b7d7b4ebbf33afb1e94803 (patch)
treece3546fb9701fcdaa1ce007fd5611e8912c9cb57 /tokio/src/sync/tests
parent466dd4a851122ab2c2b11bf44148887e359fd938 (diff)
Test some more mpsc behavior with loom (#2246)
Diffstat (limited to 'tokio/src/sync/tests')
-rw-r--r--tokio/src/sync/tests/loom_mpsc.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/tokio/src/sync/tests/loom_mpsc.rs b/tokio/src/sync/tests/loom_mpsc.rs
index 8fd6d14b..6a1a6abe 100644
--- a/tokio/src/sync/tests/loom_mpsc.rs
+++ b/tokio/src/sync/tests/loom_mpsc.rs
@@ -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());
+ });
+}