Skip to content

Commit

Permalink
test(jstzd): clean up after failed jstzd test
Browse files Browse the repository at this point in the history
  • Loading branch information
huancheng-trili committed Nov 13, 2024
1 parent 030aacd commit 8ccbd02
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions crates/jstzd/src/task/jstzd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RwLock<OctezNode>>,
baker: Arc<RwLock<OctezBaker>>,
Expand Down
19 changes: 13 additions & 6 deletions crates/jstzd/tests/jstzd_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 8ccbd02

Please sign in to comment.