Skip to content

Commit

Permalink
[nextest-runner] make delays obey SIGTSTP and SIGCONT
Browse files Browse the repository at this point in the history
Make delay timers obey these signals.
  • Loading branch information
sunshowers committed Dec 3, 2024
1 parent b55dde6 commit 97d5ab4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .config/nextest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ slow-timeout = "1s"
slow-timeout = { period = "1s", terminate-after = 2 }
retries = 2

[profile.test-retries]
retries = { backoff = "exponential", count = 3, delay = "5s" }

[profile.with-junit]
junit = { path = "report.xml" }

Expand Down
59 changes: 50 additions & 9 deletions nextest-runner/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,15 +698,12 @@ impl<'a> TestRunnerInner<'a> {
},
);

tokio::select! {
_ = tokio::time::sleep(delay) => {}
// Cancel the sleep if the run is cancelled.
_ = cancel_receiver.recv() => {
// Don't need to do anything special for this because
// cancel_receiver gets a message after
// cancelled_ref is set.
}
}
handle_delay_between_attempts(
delay,
&mut cancel_receiver,
&mut req_rx,
)
.await;
} else {
// This test failed and is out of retries.
break run_status;
Expand Down Expand Up @@ -1203,6 +1200,50 @@ fn drain_req_rx(mut receiver: UnboundedReceiver<RunUnitRequest>) {
}
}

async fn handle_delay_between_attempts(
delay: Duration,
cancel_receiver: &mut broadcast::Receiver<()>,
req_rx: &mut UnboundedReceiver<RunUnitRequest>,
) {
let mut sleep = std::pin::pin!(crate::time::pausable_sleep(delay));

#[cfg_attr(not(unix), expect(clippy::never_loop))]
loop {
tokio::select! {
_ = &mut sleep => {
// The timer has expired.
break;
}
_ = cancel_receiver.recv() => {
// The cancel signal was received.
break;
}
recv = req_rx.recv() => {
let req = recv.expect("req_rx sender is open");

match req {
#[cfg(unix)]
RunUnitRequest::Signal(SignalRequest::Stop(tx)) => {
sleep.as_mut().pause();
_ = tx.send(());
}
#[cfg(unix)]
RunUnitRequest::Signal(SignalRequest::Continue) => {
if sleep.is_paused() {
sleep.as_mut().resume();
}
}
RunUnitRequest::Signal(SignalRequest::Shutdown(_)) => {
// The run was cancelled, so go ahead and perform a
// shutdown.
break;
}
}
}
}
}
}

// It would be nice to fix this function to not have so many arguments, but this
// code is actively being refactored right now and imposing too much structure
// can cause more harm than good.
Expand Down

0 comments on commit 97d5ab4

Please sign in to comment.