Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Finomnis committed Oct 18, 2023
1 parent 1aa7772 commit ecc1695
Show file tree
Hide file tree
Showing 8 changed files with 932 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/10_request_shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl CountdownSubsystem {

async fn run(self, subsys: SubsystemHandle) -> Result<()> {
match self.countdown().cancel_on_shutdown(&subsys).await {
Ok(()) => subsys.initiate_shutdown(),
Ok(()) => subsys.request_shutdown(),
Err(CancelledByShutdown) => tracing::info!("Countdown cancelled."),
}

Expand Down
2 changes: 1 addition & 1 deletion src/into_subsystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type SubsystemFunction<Err, ErrWrapper> =
/// #[async_trait::async_trait]
/// impl IntoSubsystem<miette::Report> for MySubsystem {
/// async fn run(self, subsys: SubsystemHandle) -> Result<()> {
/// subsys.initiate_shutdown();
/// subsys.request_shutdown();
/// Ok(())
/// }
/// }
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
//! tracing::info!("Countdown cancelled.");
//! },
//! _ = countdown() => {
//! subsys.initiate_shutdown();
//! subsys.request_shutdown();
//! }
//! };
//!
Expand Down
6 changes: 3 additions & 3 deletions src/subsystem/subsystem_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,18 +288,18 @@ impl<ErrType: ErrTypeTraits> SubsystemHandle<ErrType> {
/// sleep(Duration::from_millis(1000)).await;
///
/// // Shut down the entire subsystem tree
/// subsys.initiate_shutdown();
/// subsys.request_shutdown();
///
/// Ok(())
/// }
/// ```
pub fn initiate_shutdown(&self) {
pub fn request_shutdown(&self) {
self.inner.toplevel_cancellation_token.cancel();
}

/// Triggers a shutdown of the current subsystem and all
/// of its children.
pub fn initiate_local_shutdown(&self) {
pub fn request_local_shutdown(&self) {
self.inner.cancellation_token.cancel();
}

Expand Down
7 changes: 4 additions & 3 deletions src/toplevel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
/// use tokio_graceful_shutdown::{SubsystemBuilder, SubsystemHandle, Toplevel};
///
/// async fn my_subsystem(subsys: SubsystemHandle) -> Result<()> {
/// subsys.initiate_shutdown();
/// subsys.request_shutdown();
/// Ok(())
/// }
///
Expand Down Expand Up @@ -165,7 +165,7 @@ impl<ErrType: ErrTypeTraits> Toplevel<ErrType> {
tracing::info!("All subsystems finished.");

// Not really necessary, but for good measure.
self.root_handle.initiate_shutdown();
self.root_handle.request_shutdown();

let errors = collect_errors();
let result = if errors.is_empty() {
Expand Down Expand Up @@ -203,7 +203,8 @@ impl<ErrType: ErrTypeTraits> Toplevel<ErrType> {
}

#[doc(hidden)]
pub fn get_shutdown_token(&self) -> &CancellationToken {
// Only for unit tests; not intended for public use
pub fn _get_shutdown_token(&self) -> &CancellationToken {
self.root_handle.get_cancellation_token()
}
}
2 changes: 0 additions & 2 deletions tests/common/event.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(unused)]

use tokio::sync::watch;

pub struct Event {
Expand Down
Loading

0 comments on commit ecc1695

Please sign in to comment.