Skip to content

Commit be10886

Browse files
committed
[nextest-runner] remove cancellation broadcast receiver
This functionality is now provided by the dispatcher via the request channel.
1 parent 258e6c9 commit be10886

File tree

6 files changed

+35
-24
lines changed

6 files changed

+35
-24
lines changed

nextest-runner/src/runner/dispatcher.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use debug_ignore::DebugIgnore;
2525
use quick_junit::ReportUuid;
2626
use std::{collections::BTreeMap, time::Duration};
2727
use tokio::sync::{
28-
broadcast,
2928
mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender},
3029
oneshot,
3130
};
@@ -98,7 +97,6 @@ where
9897
signal_handler: &mut SignalHandler,
9998
input_handler: &mut InputHandler,
10099
report_cancel_rx: oneshot::Receiver<()>,
101-
cancellation_sender: broadcast::Sender<()>,
102100
) -> RunnerTaskState {
103101
let mut report_cancel_rx = std::pin::pin!(report_cancel_rx);
104102

@@ -271,17 +269,17 @@ where
271269
}
272270
HandleEventResponse::Cancel(cancel) => {
273271
// A cancellation notice was received.
274-
let _ = cancellation_sender.send(());
275272
match cancel {
276273
// Some of the branches here don't do anything, but are specified
277274
// for readability.
278275
CancelEvent::Report => {
279276
// An error was produced by the reporter, and cancellation has
280277
// begun.
278+
self.broadcast_request(RunUnitRequest::OtherCancel);
281279
}
282280
CancelEvent::TestFailure => {
283-
// A test failure has caused cancellation to begin. Nothing to
284-
// do here.
281+
// A test failure has caused cancellation to begin.
282+
self.broadcast_request(RunUnitRequest::OtherCancel);
285283
}
286284
CancelEvent::Signal(req) => {
287285
// A signal has caused cancellation to begin. Let all the child

nextest-runner/src/runner/executor.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ use std::{
4545
use tokio::{
4646
process::Child,
4747
sync::{
48-
broadcast,
4948
mpsc::{UnboundedReceiver, UnboundedSender},
5049
oneshot,
5150
},
@@ -163,7 +162,6 @@ impl<'a> ExecutorContext<'a> {
163162
test_instance: TestInstance<'a>,
164163
settings: TestSettings<'a>,
165164
resp_tx: UnboundedSender<ExecutorEvent<'a>>,
166-
mut cancel_receiver: broadcast::Receiver<()>,
167165
setup_script_data: Arc<SetupScriptExecuteData<'a>>,
168166
) {
169167
debug!(test_name = test_instance.name, "running test");
@@ -268,7 +266,6 @@ impl<'a> ExecutorContext<'a> {
268266
previous_result,
269267
previous_slow,
270268
delay,
271-
&mut cancel_receiver,
272269
&mut req_rx,
273270
)
274271
.await;
@@ -464,6 +461,10 @@ impl<'a> ExecutorContext<'a> {
464461
slow_timeout.grace_period
465462
).await;
466463
}
464+
RunUnitRequest::OtherCancel => {
465+
// Ignore non-signal cancellation requests --
466+
// let the script finish.
467+
}
467468
RunUnitRequest::Query(RunUnitQuery::GetInfo(sender)) => {
468469
_ = sender.send(script.info_response(
469470
UnitState::Running {
@@ -706,6 +707,10 @@ impl<'a> ExecutorContext<'a> {
706707
slow_timeout.grace_period,
707708
).await;
708709
}
710+
RunUnitRequest::OtherCancel => {
711+
// Ignore non-signal cancellation requests --
712+
// let the test finish.
713+
}
709714
RunUnitRequest::Query(RunUnitQuery::GetInfo(tx)) => {
710715
_ = tx.send(test.info_response(
711716
UnitState::Running {
@@ -986,7 +991,6 @@ async fn handle_delay_between_attempts<'a>(
986991
previous_result: ExecutionResult,
987992
previous_slow: bool,
988993
delay: Duration,
989-
cancel_receiver: &mut broadcast::Receiver<()>,
990994
req_rx: &mut UnboundedReceiver<RunUnitRequest<'a>>,
991995
) {
992996
let mut sleep = std::pin::pin!(crate::time::pausable_sleep(delay));
@@ -999,10 +1003,6 @@ async fn handle_delay_between_attempts<'a>(
9991003
// The timer has expired.
10001004
break;
10011005
}
1002-
_ = cancel_receiver.recv() => {
1003-
// The cancel signal was received.
1004-
break;
1005-
}
10061006
recv = req_rx.recv() => {
10071007
let req = recv.expect("req_rx sender is open");
10081008

@@ -1025,6 +1025,11 @@ async fn handle_delay_between_attempts<'a>(
10251025
// shutdown.
10261026
break;
10271027
}
1028+
RunUnitRequest::OtherCancel => {
1029+
// If a cancellation was requested, break out of the
1030+
// loop.
1031+
break;
1032+
}
10281033
RunUnitRequest::Query(RunUnitQuery::GetInfo(tx)) => {
10291034
let waiting_snapshot = waiting_stopwatch.snapshot();
10301035
_ = tx.send(
@@ -1096,6 +1101,10 @@ async fn detect_fd_leaks<'a>(
10961101
RunUnitRequest::Signal(_) => {
10971102
// The process is done executing, so signals are moot.
10981103
}
1104+
RunUnitRequest::OtherCancel => {
1105+
// Ignore non-signal cancellation requests -- let the
1106+
// unit finish.
1107+
}
10991108
RunUnitRequest::Query(RunUnitQuery::GetInfo(sender)) => {
11001109
let snapshot = waiting_stopwatch.snapshot();
11011110
let resp = cx.info_response(

nextest-runner/src/runner/imp.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use quick_junit::ReportUuid;
2323
use std::{convert::Infallible, fmt, sync::Arc};
2424
use tokio::{
2525
runtime::Runtime,
26-
sync::{broadcast, mpsc::unbounded_channel, oneshot},
26+
sync::{mpsc::unbounded_channel, oneshot},
2727
task::JoinError,
2828
};
2929
use tracing::{debug, warn};
@@ -280,16 +280,10 @@ impl<'a> TestRunnerInner<'a> {
280280

281281
let ((), results) = TokioScope::scope_and_block(move |scope| {
282282
let (resp_tx, resp_rx) = unbounded_channel::<ExecutorEvent<'a>>();
283-
let (cancellation_sender, _cancel_receiver) = broadcast::channel(1);
284283

285284
// Run the dispatcher to completion in a task.
286-
let dispatcher_fut = dispatcher_cx_mut.run(
287-
resp_rx,
288-
signal_handler,
289-
input_handler,
290-
report_cancel_rx,
291-
cancellation_sender.clone(),
292-
);
285+
let dispatcher_fut =
286+
dispatcher_cx_mut.run(resp_rx, signal_handler, input_handler, report_cancel_rx);
293287
scope.spawn_cancellable(dispatcher_fut, || RunnerTaskState::Cancelled);
294288

295289
let (script_tx, mut script_rx) = unbounded_channel::<SetupScriptExecuteData<'a>>();
@@ -330,7 +324,6 @@ impl<'a> TestRunnerInner<'a> {
330324
TestGroup::Global => None,
331325
TestGroup::Custom(name) => Some(name.clone()),
332326
};
333-
let cancel_rx = cancellation_sender.subscribe();
334327
let resp_tx = resp_tx.clone();
335328
let setup_script_data = setup_script_data.clone();
336329

@@ -359,7 +352,6 @@ impl<'a> TestRunnerInner<'a> {
359352
test_instance,
360353
settings,
361354
resp_tx.clone(),
362-
cancel_rx,
363355
setup_script_data,
364356
))
365357
})

nextest-runner/src/runner/internal_events.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ impl InternalSetupScriptExecuteStatus<'_> {
183183
#[derive(Clone, Debug)]
184184
pub(super) enum RunUnitRequest<'a> {
185185
Signal(SignalRequest),
186+
/// Non-signal cancellation requests (e.g. test failures) which should cause
187+
/// tests to exit in some states.
188+
OtherCancel,
186189
Query(RunUnitQuery<'a>),
187190
}
188191

@@ -197,6 +200,7 @@ impl<'a> RunUnitRequest<'a> {
197200
#[cfg(unix)]
198201
Self::Signal(SignalRequest::Continue) => {}
199202
Self::Signal(SignalRequest::Shutdown(_)) => {}
203+
Self::OtherCancel => {}
200204
Self::Query(RunUnitQuery::GetInfo(tx)) => {
201205
// The receiver being dead isn't really important.
202206
_ = tx.send(status.info_response());

nextest-runner/src/runner/unix.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ pub(super) async fn terminate_child<'a>(
155155
}
156156
break;
157157
}
158+
RunUnitRequest::OtherCancel => {
159+
// Ignore non-signal cancellation requests (most
160+
// likely another test failed). Let the unit finish.
161+
}
158162
RunUnitRequest::Query(RunUnitQuery::GetInfo(sender)) => {
159163
let waiting_snapshot = waiting_stopwatch.snapshot();
160164
_ = sender.send(

nextest-runner/src/runner/windows.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ pub(super) async fn terminate_child<'a>(
119119
// immediately -- go to the next step.
120120
break false;
121121
}
122+
RunUnitRequest::OtherCancel => {
123+
// Ignore non-signal cancellation requests (most
124+
// likely another test failed). Let the unit finish.
125+
}
122126
RunUnitRequest::Query(RunUnitQuery::GetInfo(sender)) => {
123127
let waiting_snapshot = waiting_stopwatch.snapshot();
124128
_ = sender.send(

0 commit comments

Comments
 (0)