Skip to content

Commit e7fd0f6

Browse files
authored
Fix random fail in runtime::tokio::tests::test_spawn_and_abort (#10632)
this seems to be caused by non deterministic polling behaviour Signed-off-by: Robert Kruszewski <github@robertk.io>
1 parent 3bf14ba commit e7fd0f6

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

‎vortex-io/src/runtime/tokio.rs‎

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -198,26 +198,30 @@ mod tests {
198198
let runtime = TokioRuntime::from(tokio_rt.handle());
199199

200200
let counter = Arc::new(AtomicUsize::new(0));
201-
let c = Arc::clone(&counter);
201+
let task_counter = Arc::clone(&counter);
202202

203-
// Create a channel to ensure the future doesn't complete immediately
204-
let (send, recv) = oneshot::channel::<()>();
203+
let (started_send, started_recv) = oneshot::channel::<()>();
204+
let (mut release_send, release_recv) = oneshot::channel::<()>();
205205

206-
let (done_send, done_recv) = oneshot::channel::<()>();
207-
let fut = async move {
208-
let _done = done_send;
209-
let _ = recv.await;
210-
c.fetch_add(1, Ordering::SeqCst);
206+
let future = async move {
207+
started_send
208+
.send(())
209+
.expect("test retains the startup receiver");
210+
211+
let _ = release_recv.await;
212+
task_counter.fetch_add(1, Ordering::SeqCst);
211213
};
212-
let task = runtime.handle().spawn(fut.boxed());
213-
drop(task);
214+
let task = runtime.handle().spawn(future.boxed());
214215

215-
// Aborting is asynchronous. Keep the future blocked until cancellation finishes
216-
// so it cannot complete during an in-flight poll.
217216
tokio_rt
218-
.block_on(done_recv)
219-
.expect_err("task has terminated");
220-
assert!(send.send(()).is_err());
217+
.block_on(started_recv)
218+
.expect("spawned task must signal startup");
219+
220+
drop(task);
221+
222+
// Keeping the sender open without sending prevents normal completion.
223+
tokio_rt.block_on(release_send.closed());
224+
221225
assert_eq!(counter.load(Ordering::SeqCst), 0);
222226
}
223227
}

0 commit comments

Comments
 (0)