Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Finomnis committed Feb 7, 2024
1 parent ab370f5 commit 84af571
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion tests/integration_test_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ pub mod common;

use std::{
error::Error,
sync::{Arc, Mutex},
sync::{
atomic::{AtomicBool, Ordering},
Arc, Mutex,
},
};

use crate::common::Event;
Expand Down Expand Up @@ -247,3 +250,37 @@ async fn cancellation_token_does_not_propagate_up() {
.await;
assert!(result.is_ok());
}

#[tokio::test]
#[traced_test]
async fn subsystem_finished_works_correctly() {
let subsystem = |subsys: SubsystemHandle| async move {
subsys.on_shutdown_requested().await;
BoxedResult::Ok(())
};

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

let is_finished = AtomicBool::new(false);
tokio::join!(
async {
nested_finished.await;
is_finished.store(true, Ordering::Release);
},
async {
sleep(Duration::from_millis(20)).await;
assert_eq!(is_finished.load(Ordering::Acquire), false);

Check warning

Code scanning / clippy

used assert_eq! with a literal bool Warning test

used assert\_eq! with a literal bool
nested.initiate_shutdown();
sleep(Duration::from_millis(20)).await;
assert_eq!(is_finished.load(Ordering::Acquire), true);

Check warning

Code scanning / clippy

used assert_eq! with a literal bool Warning test

used assert\_eq! with a literal bool
}
);
});

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

0 comments on commit 84af571

Please sign in to comment.