Skip to content

Commit

Permalink
Remove obsolete runner tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Finomnis committed Oct 18, 2023
1 parent 8836224 commit 1aa7772
Showing 1 changed file with 0 additions and 258 deletions.
258 changes: 0 additions & 258 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,261 +110,3 @@ async fn run_subsystem<Fut, Subsys, ErrType: ErrTypeTraits, Err>(
// This is the main mechanism that forwards a cancellation to all the children.
joiner_token.downgrade().join().await;
}

/*
#[cfg(test)]
mod tests {
use std::sync::{Arc, Mutex};
use tokio::{
sync::oneshot,
time::{timeout, Duration},
};
use super::*;
use crate::{subsystem::root_handle, BoxedError};
fn create_result_and_guard() -> (oneshot::Receiver<StopReason>, AliveGuard) {
let (sender, receiver) = oneshot::channel();
let guard = AliveGuard::new();
guard.on_finished({
move |r| {
sender.send(r).unwrap();
}
});
(receiver, guard)
}
mod run_subsystem {
use super::*;
#[tokio::test]
async fn finish() {
let (mut result, guard) = create_result_and_guard();
run_subsystem(
Arc::from(""),
|_| async { Result::<(), BoxedError>::Ok(()) },
root_handle(),
guard,
)
.await;
assert!(matches!(result.try_recv(), Ok(StopReason::Finish)));
}
#[tokio::test]
async fn panic() {
let (mut result, guard) = create_result_and_guard();
run_subsystem::<_, _, _, BoxedError>(
Arc::from(""),
|_| async {
panic!();
},
root_handle(),
guard,
)
.await;
assert!(matches!(result.try_recv(), Ok(StopReason::Panic)));
}
#[tokio::test]
async fn error() {
let (mut result, guard) = create_result_and_guard();
run_subsystem::<_, _, _, BoxedError>(
Arc::from(""),
|_| async { Err(String::from("").into()) },
root_handle(),
guard,
)
.await;
assert!(matches!(result.try_recv(), Ok(StopReason::Error(_))));
}
#[tokio::test]
async fn cancelled_with_delay() {
let (mut result, guard) = create_result_and_guard();
let (drop_sender, mut drop_receiver) = tokio::sync::mpsc::channel::<()>(1);
let timeout_result = timeout(
Duration::from_millis(100),
run_subsystem::<_, _, _, BoxedError>(
Arc::from(""),
|_| async move {
drop_sender.send(()).await.unwrap();
std::future::pending().await
},
root_handle(),
guard,
),
)
.await;
assert!(timeout_result.is_err());
drop(timeout_result);
// Make sure we are executing the subsystem
let recv_result = timeout(Duration::from_millis(100), drop_receiver.recv())
.await
.unwrap();
assert!(recv_result.is_some());
// Make sure the subsystem got cancelled
let recv_result = timeout(Duration::from_millis(100), drop_receiver.recv())
.await
.unwrap();
assert!(recv_result.is_none());
assert!(matches!(result.try_recv(), Ok(StopReason::Cancelled)));
}
#[tokio::test]
async fn cancelled_immediately() {
let (mut result, guard) = create_result_and_guard();
let (drop_sender, mut drop_receiver) = tokio::sync::mpsc::channel::<()>(1);
let _ = run_subsystem::<_, _, _, BoxedError>(
Arc::from(""),
|_| async move {
drop_sender.send(()).await.unwrap();
std::future::pending().await
},
root_handle(),
guard,
);
// Make sure we are executing the subsystem
let recv_result = timeout(Duration::from_millis(100), drop_receiver.recv())
.await
.unwrap();
assert!(recv_result.is_none());
assert!(matches!(result.try_recv(), Ok(StopReason::Cancelled)));
}
}
mod subsystem_runner {
use crate::utils::JoinerToken;
use super::*;
#[tokio::test]
async fn finish() {
let (mut result, guard) = create_result_and_guard();
let runner = SubsystemRunner::new(
Arc::from(""),
|_| async { Result::<(), BoxedError>::Ok(()) },
root_handle(),
guard,
);
let result = timeout(Duration::from_millis(200), result).await.unwrap();
assert!(matches!(result, Ok(StopReason::Finish)));
}
#[tokio::test]
async fn panic() {
let (mut result, guard) = create_result_and_guard();
let runner = SubsystemRunner::new::<_, _, _, BoxedError>(
Arc::from(""),
|_| async {
panic!();
},
root_handle(),
guard,
);
let result = timeout(Duration::from_millis(200), result).await.unwrap();
assert!(matches!(result, Ok(StopReason::Panic)));
}
#[tokio::test]
async fn error() {
let (mut result, guard) = create_result_and_guard();
let runner = SubsystemRunner::new::<_, _, _, BoxedError>(
Arc::from(""),
|_| async { Err(String::from("").into()) },
root_handle(),
guard,
);
let result = timeout(Duration::from_millis(200), result).await.unwrap();
assert!(matches!(result, Ok(StopReason::Error(_))));
}
#[tokio::test]
async fn cancelled_with_delay() {
let (mut result, guard) = create_result_and_guard();
let (drop_sender, mut drop_receiver) = tokio::sync::mpsc::channel::<()>(1);
let runner = SubsystemRunner::new::<_, _, _, BoxedError>(
Arc::from(""),
|_| async move {
drop_sender.send(()).await.unwrap();
std::future::pending().await
},
root_handle(),
guard,
);
// Make sure we are executing the subsystem
let recv_result = timeout(Duration::from_millis(100), drop_receiver.recv())
.await
.unwrap();
assert!(recv_result.is_some());
drop(runner);
// Make sure the subsystem got cancelled
let recv_result = timeout(Duration::from_millis(100), drop_receiver.recv())
.await
.unwrap();
assert!(recv_result.is_none());
let result = timeout(Duration::from_millis(200), result).await.unwrap();
assert!(matches!(result, Ok(StopReason::Cancelled)));
}
#[tokio::test]
async fn cancelled_immediately() {
let (mut result, guard) = create_result_and_guard();
let (mut joiner_token, _) = JoinerToken::new(|_| None);
let _ = SubsystemRunner::new::<_, _, _, BoxedError>(
Arc::from(""),
{
let (joiner_token, _) = joiner_token.child_token(|_| None);
|_| async move {
let joiner_token = joiner_token;
std::future::pending().await
}
},
root_handle(),
guard,
);
// Make sure the subsystem got cancelled
timeout(Duration::from_millis(100), joiner_token.join_children())
.await
.unwrap();
let result = timeout(Duration::from_millis(200), result).await.unwrap();
assert!(matches!(result, Ok(StopReason::Cancelled)));
}
}
}
*/

0 comments on commit 1aa7772

Please sign in to comment.