Skip to content

Commit

Permalink
Speed up mpsc_stress test
Browse files Browse the repository at this point in the history
  • Loading branch information
mejrs committed Nov 22, 2022
1 parent 736c675 commit f2830f2
Showing 1 changed file with 51 additions and 16 deletions.
67 changes: 51 additions & 16 deletions src/test/ui/threads-sendsync/mpsc_stress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ fn shared_close_sender_does_not_lose_messages_iter() {

#[test]
fn shared_close_sender_does_not_lose_messages() {
for _ in 0..10000 {
shared_close_sender_does_not_lose_messages_iter();
}
with_minimum_timer_resolution(|| {
for _ in 0..10000 {
shared_close_sender_does_not_lose_messages_iter();
}
});
}


Expand Down Expand Up @@ -96,17 +98,11 @@ fn concurrent_recv_timeout_and_upgrade_iter() {

#[test]
fn concurrent_recv_timeout_and_upgrade() {
// FIXME: fix and enable
if true { return }

// at the moment of writing this test fails like this:
// thread '<unnamed>' panicked at 'assertion failed: `(left == right)`
// left: `4561387584`,
// right: `0`', libstd/sync/mpsc/shared.rs:253:13

for _ in 0..10000 {
concurrent_recv_timeout_and_upgrade_iter();
}
with_minimum_timer_resolution(|| {
for _ in 0..10000 {
concurrent_recv_timeout_and_upgrade_iter();
}
});
}


Expand Down Expand Up @@ -159,7 +155,46 @@ fn concurrent_writes_iter() {

#[test]
fn concurrent_writes() {
for _ in 0..100 {
concurrent_writes_iter();
with_minimum_timer_resolution(|| {
for _ in 0..100 {
concurrent_writes_iter();
}
});
}

#[cfg(windows)]
pub mod timeapi {
#![allow(non_snake_case)]
use std::ffi::c_uint;

pub const TIMERR_NOERROR: c_uint = 0;

#[link(name = "winmm")]
extern "system" {
pub fn timeBeginPeriod(uPeriod: c_uint) -> c_uint;
pub fn timeEndPeriod(uPeriod: c_uint) -> c_uint;
}
}

/// Window's minimum sleep time can be as much as 16ms.
// This function evaluates the closure with this resolution
// set as low as possible.
///
/// This takes the above test's duration from 10000*16/1000/60=2.67 minutes to ~16 seconds.
fn with_minimum_timer_resolution(f: impl Fn()) {
#[cfg(windows)]
unsafe {
let ret = timeapi::timeBeginPeriod(1);
assert_eq!(ret, timeapi::TIMERR_NOERROR);

f();

let ret = timeapi::timeEndPeriod(1);
assert_eq!(ret, timeapi::TIMERR_NOERROR);
}

#[cfg(not(windows))]
{
f();
}
}

0 comments on commit f2830f2

Please sign in to comment.