Skip to content

Commit

Permalink
wip fix channel
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Oct 14, 2020
1 parent 6ec318f commit 1739f79
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 11 deletions.
1 change: 1 addition & 0 deletions crossbeam-channel/tests/after.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Tests for the after channel flavor.
#![cfg(not(miri))] // todo

use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
Expand Down
1 change: 1 addition & 0 deletions crossbeam-channel/tests/array.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Tests for the array channel flavor.
#![cfg(not(miri))] // todo

use std::any::Any;
use std::sync::atomic::AtomicUsize;
Expand Down
2 changes: 2 additions & 0 deletions crossbeam-channel/tests/golang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
//! - https://golang.org/LICENSE
//! - https://golang.org/PATENTS
#![cfg(not(miri))] // todo

use std::alloc::{GlobalAlloc, Layout, System};
use std::any::Any;
use std::cell::Cell;
Expand Down
1 change: 1 addition & 0 deletions crossbeam-channel/tests/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ fn recv_iter_break() {
.unwrap();
}

#[cfg_attr(miri, ignore)] // todo
#[test]
fn recv_try_iter() {
let (request_s, request_r) = unbounded();
Expand Down
20 changes: 20 additions & 0 deletions crossbeam-channel/tests/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ fn disconnect_wakes_receiver() {

#[test]
fn spsc() {
#[cfg(miri)]
const COUNT: usize = 500;
#[cfg(not(miri))]
const COUNT: usize = 100_000;

let (s, r) = unbounded();
Expand All @@ -261,6 +264,9 @@ fn spsc() {

#[test]
fn mpmc() {
#[cfg(miri)]
const COUNT: usize = 500;
#[cfg(not(miri))]
const COUNT: usize = 25_000;
const THREADS: usize = 4;

Expand Down Expand Up @@ -295,6 +301,9 @@ fn mpmc() {

#[test]
fn stress_oneshot() {
#[cfg(miri)]
const COUNT: usize = 500;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

for _ in 0..COUNT {
Expand All @@ -308,6 +317,7 @@ fn stress_oneshot() {
}
}

#[cfg_attr(miri, ignore)] // todo
#[test]
fn stress_iter() {
const COUNT: usize = 100_000;
Expand Down Expand Up @@ -371,6 +381,7 @@ fn stress_timeout_two_threads() {
.unwrap();
}

#[cfg_attr(miri, ignore)] // todo
#[test]
fn drops() {
static DROPS: AtomicUsize = AtomicUsize::new(0);
Expand Down Expand Up @@ -421,6 +432,9 @@ fn drops() {

#[test]
fn linearizable() {
#[cfg(miri)]
const COUNT: usize = 500;
#[cfg(not(miri))]
const COUNT: usize = 25_000;
const THREADS: usize = 4;

Expand All @@ -441,6 +455,9 @@ fn linearizable() {

#[test]
fn fairness() {
#[cfg(miri)]
const COUNT: usize = 500;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

let (s1, r1) = unbounded::<()>();
Expand All @@ -463,6 +480,9 @@ fn fairness() {

#[test]
fn fairness_duplicates() {
#[cfg(miri)]
const COUNT: usize = 500;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

let (s, r) = unbounded();
Expand Down
47 changes: 36 additions & 11 deletions crossbeam-channel/tests/mpsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ mod channel_tests {
assert!(tx2.send(1).is_err());
}

#[cfg_attr(miri, ignore)] //todo
#[test]
fn port_gone_concurrent() {
let (tx, rx) = channel::<i32>();
Expand All @@ -274,6 +275,7 @@ mod channel_tests {
t.join().unwrap();
}

#[cfg_attr(miri, ignore)] //todo
#[test]
fn port_gone_concurrent_shared() {
let (tx, rx) = channel::<i32>();
Expand Down Expand Up @@ -314,20 +316,28 @@ mod channel_tests {

#[test]
fn stress() {
#[cfg(miri)]
const COUNT: usize = 500;
#[cfg(not(miri))]
const COUNT: usize = 10000;

let (tx, rx) = channel::<i32>();
let t = thread::spawn(move || {
for _ in 0..10000 {
for _ in 0..COUNT {
tx.send(1).unwrap();
}
});
for _ in 0..10000 {
for _ in 0..COUNT {
assert_eq!(rx.recv().unwrap(), 1);
}
t.join().ok().unwrap();
}

#[test]
fn stress_shared() {
#[cfg(miri)]
const AMT: u32 = 500;
#[cfg(not(miri))]
const AMT: u32 = 10000;
const NTHREADS: u32 = 8;
let (tx, rx) = channel::<i32>();
Expand Down Expand Up @@ -735,12 +745,16 @@ mod channel_tests {

#[test]
fn recv_a_lot() {
#[cfg(miri)]
const COUNT: usize = 500;
#[cfg(not(miri))]
const COUNT: usize = 10000;
// Regression test that we don't run out of stack in scheduler context
let (tx, rx) = channel();
for _ in 0..10000 {
for _ in 0..COUNT {
tx.send(()).unwrap();
}
for _ in 0..10000 {
for _ in 0..COUNT {
rx.recv().unwrap();
}
}
Expand Down Expand Up @@ -841,6 +855,7 @@ mod channel_tests {
t.join().unwrap();
}

#[cfg_attr(miri, ignore)]
#[test]
fn test_recv_try_iter() {
let (request_tx, request_rx) = channel();
Expand Down Expand Up @@ -955,6 +970,7 @@ mod channel_tests {
}

// Source: https://github.com/rust-lang/rust/blob/master/src/libstd/sync/mpsc/mod.rs
#[cfg(not(miri))] // unsupported operation: the main thread terminated without waiting for other threads
mod sync_channel_tests {
use super::*;

Expand Down Expand Up @@ -1079,24 +1095,28 @@ mod sync_channel_tests {

#[test]
fn stress() {
const COUNT: usize = 10000;

let (tx, rx) = sync_channel::<i32>(0);
let t = thread::spawn(move || {
for _ in 0..10000 {
for _ in 0..COUNT {
tx.send(1).unwrap();
}
});
for _ in 0..10000 {
for _ in 0..COUNT {
assert_eq!(rx.recv().unwrap(), 1);
}
t.join().unwrap();
}

#[test]
fn stress_recv_timeout_two_threads() {
const COUNT: usize = 10000;

let (tx, rx) = sync_channel::<i32>(0);

let t = thread::spawn(move || {
for _ in 0..10000 {
for _ in 0..COUNT {
tx.send(1).unwrap();
}
});
Expand All @@ -1113,7 +1133,7 @@ mod sync_channel_tests {
}
}

assert_eq!(recv_count, 10000);
assert_eq!(recv_count, COUNT);
t.join().unwrap();
}

Expand Down Expand Up @@ -1449,12 +1469,14 @@ mod sync_channel_tests {

#[test]
fn recv_a_lot() {
const COUNT: usize = 10000;

// Regression test that we don't run out of stack in scheduler context
let (tx, rx) = sync_channel(10000);
for _ in 0..10000 {
let (tx, rx) = sync_channel(COUNT);
for _ in 0..COUNT {
tx.send(()).unwrap();
}
for _ in 0..10000 {
for _ in 0..COUNT {
rx.recv().unwrap();
}
}
Expand Down Expand Up @@ -1792,6 +1814,9 @@ mod select_tests {

#[test]
fn stress() {
#[cfg(miri)]
const AMT: i32 = 500;
#[cfg(not(miri))]
const AMT: i32 = 10000;
let (tx1, rx1) = channel::<i32>();
let (tx2, rx2) = channel::<i32>();
Expand Down
15 changes: 15 additions & 0 deletions crossbeam-channel/tests/ready.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,9 @@ fn nesting() {

#[test]
fn stress_recv() {
#[cfg(miri)]
const COUNT: usize = 500;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

let (s1, r1) = unbounded();
Expand Down Expand Up @@ -527,6 +530,9 @@ fn stress_recv() {

#[test]
fn stress_send() {
#[cfg(miri)]
const COUNT: usize = 500;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

let (s1, r1) = bounded(0);
Expand Down Expand Up @@ -561,6 +567,9 @@ fn stress_send() {

#[test]
fn stress_mixed() {
#[cfg(miri)]
const COUNT: usize = 500;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

let (s1, r1) = bounded(0);
Expand Down Expand Up @@ -724,6 +733,9 @@ fn channel_through_channel() {

#[test]
fn fairness1() {
#[cfg(miri)]
const COUNT: usize = 500;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

let (s1, r1) = bounded::<()>(COUNT);
Expand Down Expand Up @@ -769,6 +781,9 @@ fn fairness1() {

#[test]
fn fairness2() {
#[cfg(miri)]
const COUNT: usize = 500;
#[cfg(not(miri))]
const COUNT: usize = 100_000;

let (s1, r1) = unbounded::<()>();
Expand Down
25 changes: 25 additions & 0 deletions crossbeam-channel/tests/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ fn both_ready() {
.unwrap();
}

#[cfg_attr(miri, ignore)]
#[test]
fn loop_try() {
const RUNS: usize = 20;
Expand Down Expand Up @@ -690,6 +691,9 @@ fn nesting() {

#[test]
fn stress_recv() {
#[cfg(miri)]
const COUNT: usize = 500;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

let (s1, r1) = unbounded();
Expand Down Expand Up @@ -728,6 +732,9 @@ fn stress_recv() {

#[test]
fn stress_send() {
#[cfg(miri)]
const COUNT: usize = 500;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

let (s1, r1) = bounded(0);
Expand Down Expand Up @@ -763,6 +770,9 @@ fn stress_send() {

#[test]
fn stress_mixed() {
#[cfg(miri)]
const COUNT: usize = 500;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

let (s1, r1) = bounded(0);
Expand Down Expand Up @@ -1000,6 +1010,9 @@ fn channel_through_channel() {

#[test]
fn linearizable_try() {
#[cfg(miri)]
const COUNT: usize = 500;
#[cfg(not(miri))]
const COUNT: usize = 100_000;

for step in 0..2 {
Expand Down Expand Up @@ -1052,6 +1065,9 @@ fn linearizable_try() {

#[test]
fn linearizable_timeout() {
#[cfg(miri)]
const COUNT: usize = 500;
#[cfg(not(miri))]
const COUNT: usize = 100_000;

for step in 0..2 {
Expand Down Expand Up @@ -1104,6 +1120,9 @@ fn linearizable_timeout() {

#[test]
fn fairness1() {
#[cfg(miri)]
const COUNT: usize = 500;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

let (s1, r1) = bounded::<()>(COUNT);
Expand Down Expand Up @@ -1150,6 +1169,9 @@ fn fairness1() {

#[test]
fn fairness2() {
#[cfg(miri)]
const COUNT: usize = 500;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

let (s1, r1) = unbounded::<()>();
Expand Down Expand Up @@ -1266,6 +1288,9 @@ fn send_and_clone() {

#[test]
fn reuse() {
#[cfg(miri)]
const COUNT: usize = 500;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

let (s1, r1) = bounded(0);
Expand Down
Loading

0 comments on commit 1739f79

Please sign in to comment.