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 15, 2024
1 parent 616a392 commit 7f885a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 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 @@ -18,6 +18,7 @@ use serde::Serialize;
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
32 changes: 19 additions & 13 deletions crates/jstzd/tests/jstzd_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,32 @@ 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;
let octez_client = OctezClient::new(config.octez_client_config().clone());
check_bootstrap_contracts(&octez_client).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);

assert!(jstzd.health_check().await);
let octez_client = OctezClient::new(config.octez_client_config().clone());
check_bootstrap_contracts(&octez_client).await;
fetch_config_test(config, jstzd_port).await;

fetch_config_test(config, jstzd_port).await;

reqwest::Client::new()
.put(&format!("http://localhost:{}/shutdown", jstzd_port))
.send()
.await
.unwrap();
reqwest::Client::new()
.put(&format!("http://localhost:{}/shutdown", jstzd_port))
.send()
.await
.unwrap();

ensure_jstzd_components_are_down(&rpc_endpoint, jstzd_port).await;
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 7f885a2

Please sign in to comment.