Skip to content

Commit 7f917d2

Browse files
committed
run: test that error from one op stops the others
Adds a regression test which verifies that if an operation is stopped due to an error, then other operations will be stopped as well. This issue was found during the review of this pull request, it was not present in master version this PR was based on.
1 parent 07de887 commit 7f917d2

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/run.rs

+29
Original file line numberDiff line numberDiff line change
@@ -617,4 +617,33 @@ mod tests {
617617
test(21, 20, true).await;
618618
test(30, 20, true).await;
619619
}
620+
621+
#[tokio::test]
622+
#[ntest::timeout(1000)]
623+
async fn test_stops_after_one_fails() {
624+
struct Op(bool);
625+
626+
make_runnable!(Op);
627+
impl Op {
628+
async fn execute(&mut self, _ctx: &OperationContext) -> Result<ControlFlow<()>> {
629+
// Yield so that we don't get stuck in a loop and block the executor thread
630+
tokio::task::yield_now().await;
631+
if self.0 {
632+
Ok(ControlFlow::Continue(()))
633+
} else {
634+
Err(anyhow::anyhow!("error"))
635+
}
636+
}
637+
}
638+
639+
let counter = AtomicU64::new(0);
640+
let mut cfg = make_test_cfg(move || {
641+
let id = counter.fetch_add(1, Ordering::Relaxed);
642+
Op(id > 0) // Operation with id==0 always fail, others always succeed
643+
});
644+
cfg.concurrency = 3;
645+
646+
let (_, fut) = run(cfg);
647+
fut.await.unwrap_err(); // Error from one task should stop other tasks
648+
}
620649
}

0 commit comments

Comments
 (0)