Skip to content

Commit 4c2a1db

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 80d1de6 commit 4c2a1db

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

0 commit comments

Comments
 (0)