Skip to content

Commit

Permalink
Add test for cancellation token
Browse files Browse the repository at this point in the history
  • Loading branch information
Finomnis committed Nov 21, 2023
1 parent 4a1245e commit a022ecd
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/integration_test_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,29 @@ async fn shutdown_through_signal_2() {
},
);
}

#[tokio::test]
#[traced_test]
async fn cancellation_token() {
let subsystem = |subsys: SubsystemHandle| async move {
let cancellation_token = subsys.create_cancellation_token();

assert!(!cancellation_token.is_cancelled());
subsys.on_shutdown_requested().await;
assert!(cancellation_token.is_cancelled());

BoxedResult::Ok(())
};

let toplevel = Toplevel::new(move |s| async move {
s.start(SubsystemBuilder::new("subsys", subsystem));

sleep(Duration::from_millis(100)).await;
s.request_shutdown();
});

let result = toplevel
.handle_shutdown_requests(Duration::from_millis(400))
.await;
assert!(result.is_ok());
}

0 comments on commit a022ecd

Please sign in to comment.