diff --git a/tools/ibc-test/src/framework/binary/node.rs b/tools/ibc-test/src/framework/binary/node.rs index 1e5ea7d42..f144c53da 100644 --- a/tools/ibc-test/src/framework/binary/node.rs +++ b/tools/ibc-test/src/framework/binary/node.rs @@ -48,9 +48,6 @@ where let _node_process_a = node_a.process.clone(); let _node_process_b = node_b.process.clone(); - // wait for the preperation of Axon and CKB - std::thread::sleep(Duration::from_secs(30)); - // start cell-emitter if only one part of connected chains is Axon let chain_types = ( &node_a.chain_driver.chain_type, @@ -60,12 +57,14 @@ where let axon_port = node_a.chain_driver.rpc_port; let ckb_port = node_b.chain_driver.rpc_port; println!("start cell-emiter for Axon:{axon_port} and CKB:{ckb_port}"); - prepare_cell_emitter(axon_port, ckb_port)?; + let emitter = prepare_cell_emitter(axon_port, ckb_port)?; + config.extra_process.replace(Some(emitter)); } else if matches!(chain_types, (&ChainType::Ckb, &ChainType::Axon)) { let axon_port = node_b.chain_driver.rpc_port; let ckb_port = node_a.chain_driver.rpc_port; println!("start cell-emiter for Axon:{axon_port} and CKB:{ckb_port}"); - prepare_cell_emitter(axon_port, ckb_port)?; + let emitter = prepare_cell_emitter(axon_port, ckb_port)?; + config.extra_process.replace(Some(emitter)); } eprintln!("Node is initialized, Starting running inner test.........."); diff --git a/tools/ibc-test/src/framework/utils/common.rs b/tools/ibc-test/src/framework/utils/common.rs index 8784a378a..8dc95763c 100644 --- a/tools/ibc-test/src/framework/utils/common.rs +++ b/tools/ibc-test/src/framework/utils/common.rs @@ -11,7 +11,7 @@ use secp256k1::{ SecretKey, }; use std::path::PathBuf; -use std::process::{Command, Stdio}; +use std::process::{Child, Command}; use std::str::FromStr; use tokio::runtime::Runtime; @@ -65,14 +65,14 @@ pub fn transfer_port_id(chain_type: ChainType) -> PortId { } } -pub fn prepare_cell_emitter(axon_port: u16, ckb_port: u16) -> Result<(), Error> { +pub fn prepare_cell_emitter(axon_port: u16, ckb_port: u16) -> Result { let listen_port = rngs::OsRng.gen_range(9000..10000); let store_path = std::env::current_dir() .unwrap() .join(format!("emitter-store-{listen_port}")); std::fs::create_dir(&store_path) .map_err(|err| eyre!("failed to create emitter store path: {err}"))?; - Command::new("emitter") + let emitter_thread = Command::new("emitter") .arg("-c") .arg(format!("http://127.0.0.1:{ckb_port}")) .arg("--i") @@ -81,8 +81,7 @@ pub fn prepare_cell_emitter(axon_port: u16, ckb_port: u16) -> Result<(), Error> .arg(format!("127.0.0.1:{listen_port}")) .arg("-s") .arg(store_path) - .stdout(Stdio::null()) .spawn() .map_err(|err| eyre!("failed to start emitter: {err}"))?; - Ok(()) + Ok(emitter_thread) } diff --git a/tools/test-framework/src/bootstrap/init.rs b/tools/test-framework/src/bootstrap/init.rs index 45a102127..aa3ff8d97 100644 --- a/tools/test-framework/src/bootstrap/init.rs +++ b/tools/test-framework/src/bootstrap/init.rs @@ -5,8 +5,10 @@ use eyre::Report as Error; use ibc_relayer_cli::components::enable_ansi; +use std::cell::RefCell; use std::env; use std::fs; +use std::sync::Arc; use std::sync::Once; use tracing_subscriber::{ self as ts, @@ -65,6 +67,7 @@ pub fn init_test() -> Result { account_prefixes, hang_on_fail, bootstrap_with_random_ids: false, + extra_process: Arc::new(RefCell::new(None)), }) } diff --git a/tools/test-framework/src/types/config.rs b/tools/test-framework/src/types/config.rs index 4ef22f5a0..9d83733b6 100644 --- a/tools/test-framework/src/types/config.rs +++ b/tools/test-framework/src/types/config.rs @@ -3,7 +3,7 @@ */ use core::fmt::Debug; -use std::path::PathBuf; +use std::{cell::RefCell, path::PathBuf, process::Child, sync::Arc}; /** The test config to be passed to each test case. Currently this is loaded @@ -58,4 +58,20 @@ pub struct TestConfig { pub hang_on_fail: bool, pub bootstrap_with_random_ids: bool, + + pub extra_process: Arc>>, +} + +impl Drop for TestConfig { + fn drop(&mut self) { + println!("release cell-emitter child process"); + let mut process = self.extra_process.borrow_mut(); + if process.is_some() { + process + .as_mut() + .unwrap() + .kill() + .expect("kill extra process"); + } + } }