diff --git a/crates/jstzd/src/task/jstzd.rs b/crates/jstzd/src/task/jstzd.rs index 1ad5939f3..e95d511e3 100644 --- a/crates/jstzd/src/task/jstzd.rs +++ b/crates/jstzd/src/task/jstzd.rs @@ -17,6 +17,7 @@ use octez::r#async::{ use std::sync::Arc; use tokio::{net::TcpListener, sync::RwLock, task::JoinHandle}; +#[derive(Clone)] struct Jstzd { octez_node: Arc>, baker: Arc>, diff --git a/crates/jstzd/tests/jstzd_test.rs b/crates/jstzd/tests/jstzd_test.rs index 7db13b369..40f076854 100644 --- a/crates/jstzd/tests/jstzd_test.rs +++ b/crates/jstzd/tests/jstzd_test.rs @@ -16,18 +16,25 @@ async fn jstzd_test() { let rpc_endpoint = Endpoint::localhost(unused_port()); let jstzd_port = unused_port(); let (mut jstzd, config) = create_jstzd_server(&rpc_endpoint, jstzd_port).await; + let mut copy = jstzd.clone(); - jstzd.run().await.unwrap(); - ensure_jstzd_components_are_up(&rpc_endpoint, jstzd_port).await; - assert!(jstzd.health_check().await); + // wrapping the test like this so that we can still call `stop` at the end of the test + // to clean up everything should the test fail and panic + let res = tokio::spawn(async move { + copy.run().await.unwrap(); + ensure_jstzd_components_are_up(&rpc_endpoint, jstzd_port).await; + assert!(copy.health_check().await); - fetch_config_test(config, jstzd_port).await; + fetch_config_test(config, jstzd_port).await; - jstzd.stop().await.unwrap(); - ensure_jstzd_components_are_down(&rpc_endpoint, jstzd_port).await; + copy.stop().await.unwrap(); + ensure_jstzd_components_are_down(&rpc_endpoint, jstzd_port).await; + }) + .await; // stop should be idempotent and thus should be okay after jstzd is already stopped jstzd.stop().await.unwrap(); + assert!(res.is_ok()) } async fn create_jstzd_server(