Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions library/std/tests/sync/mpmc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,8 @@ fn oneshot_single_thread_recv_timeout() {
#[test]
fn stress_recv_timeout_two_threads() {
let (tx, rx) = channel();
let stress = stress_factor() + 100;
let timeout = Duration::from_millis(100);
let stress = stress_factor() + 50;
let timeout = Duration::from_millis(5);

thread::spawn(move || {
for i in 0..stress {
Expand All @@ -475,18 +475,23 @@ fn stress_recv_timeout_two_threads() {
});

let mut recv_count = 0;
let mut got_timeout = false;
loop {
match rx.recv_timeout(timeout) {
Ok(n) => {
assert_eq!(n, 1usize);
recv_count += 1;
}
Err(RecvTimeoutError::Timeout) => continue,
Err(RecvTimeoutError::Timeout) => {
got_timeout = true;
continue;
}
Err(RecvTimeoutError::Disconnected) => break,
}
}

assert_eq!(recv_count, stress);
assert!(got_timeout);
}

#[test]
Expand Down
11 changes: 8 additions & 3 deletions library/std/tests/sync/mpsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ fn oneshot_single_thread_recv_timeout() {
#[test]
fn stress_recv_timeout_two_threads() {
let (tx, rx) = channel();
let stress = stress_factor() + 100;
let timeout = Duration::from_millis(100);
let stress = stress_factor() + 50;
let timeout = Duration::from_millis(5);

thread::spawn(move || {
for i in 0..stress {
Expand All @@ -438,18 +438,23 @@ fn stress_recv_timeout_two_threads() {
});

let mut recv_count = 0;
let mut got_timeout = false;
loop {
match rx.recv_timeout(timeout) {
Ok(n) => {
assert_eq!(n, 1usize);
recv_count += 1;
}
Err(RecvTimeoutError::Timeout) => continue,
Err(RecvTimeoutError::Timeout) => {
got_timeout = true;
continue;
}
Err(RecvTimeoutError::Disconnected) => break,
}
}

assert_eq!(recv_count, stress);
assert!(got_timeout);
}

#[test]
Expand Down
Loading