diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-01-02 22:18:03 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-02 22:18:03 +0000 |
commit | 5359b8e945fc5b07a094de079367df166c5a1d10 (patch) | |
tree | 56b77243a488521b7ba53f3f5e9ea8d4298664ff /test | |
parent | ee0543f126f2161302ab375dd657d3ef8b423f8a (diff) | |
parent | e5b9b972b2e61a0bda96f1fadb2fa3b60a4b7690 (diff) | |
download | nix-5359b8e945fc5b07a094de079367df166c5a1d10.zip |
Merge #1626
1626: Fix intermittency in test_timer::alarm_fires r=rtzoeller a=asomers
The test was disabling the signal handler before disabling the timer.
Fix intermittent failures but reversing the cleanup order.
Also, speed up the timer to make the test suite complete faster.
Co-authored-by: Alan Somers <asomers@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/test_timer.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/test/test_timer.rs b/test/test_timer.rs index 31a740b0..d07d9633 100644 --- a/test/test_timer.rs +++ b/test/test_timer.rs @@ -23,6 +23,7 @@ fn alarm_fires() { // Avoid interfering with other signal using tests by taking a mutex shared // among other tests in this crate. let _m = crate::SIGNAL_MTX.lock(); + const TIMER_PERIOD: Duration = Duration::from_millis(100); // // Setup @@ -44,7 +45,7 @@ fn alarm_fires() { si_value: 0, }); let mut timer = Timer::new(clockid, sigevent).expect("failed to create timer"); - let expiration = Expiration::Interval(Duration::from_millis(250).into()); + let expiration = Expiration::Interval(TIMER_PERIOD.into()); let flags = TimerSetTimeFlags::empty(); timer.set(expiration, flags).expect("could not set timer"); @@ -73,7 +74,7 @@ fn alarm_fires() { // is never called something has gone sideways and the test fails. let starttime = Instant::now(); loop { - thread::sleep(Duration::from_millis(500)); + thread::sleep(2 * TIMER_PERIOD); if ALARM_CALLED.load(Ordering::Acquire) { break; } @@ -82,9 +83,16 @@ fn alarm_fires() { } } - // Replace the old signal handler now that we've completed the test. If the - // test fails this process panics, so the fact we might not get here is - // okay. + // Cleanup: + // 1) deregister the OS's timer. + // 2) Wait for a full timer period, since POSIX does not require that + // disabling the timer will clear pending signals, and on NetBSD at least + // it does not. + // 2) Replace the old signal handler now that we've completed the test. If + // the test fails this process panics, so the fact we might not get here + // is okay. + drop(timer); + thread::sleep(TIMER_PERIOD); unsafe { sigaction(SIG, &old_handler).expect("unable to reset signal handler"); } |