From 0a4c9ea5581cbcc472cb9de94f8f4b6155ceeb7b Mon Sep 17 00:00:00 2001 From: liyukun Date: Wed, 20 Dec 2023 16:18:31 +0800 Subject: [PATCH] chore: follow emitter sub process --- .github/workflows/ibc-test.yaml | 4 ++-- tools/ibc-test/src/framework/binary/node.rs | 9 ++++----- tools/ibc-test/src/framework/utils/axon.rs | 2 +- tools/ibc-test/src/framework/utils/common.rs | 11 +++++------ tools/test-framework/src/bootstrap/init.rs | 3 +++ tools/test-framework/src/types/config.rs | 18 +++++++++++++++++- 6 files changed, 32 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ibc-test.yaml b/.github/workflows/ibc-test.yaml index a5e385307..b900b78b0 100644 --- a/.github/workflows/ibc-test.yaml +++ b/.github/workflows/ibc-test.yaml @@ -29,8 +29,8 @@ jobs: env: SRC_DIR: ${{ github.workspace }}/ibc-test-src # https://github.com/axonweb3/axon/commits/forcerelay-dev - AXON_COMMIT: 922fc3858b4c470a39b3ae98a479980e774896b5 - IBC_CONTRACT_COMMIT: c5417573ec15c8aaab048caa1ec5f3bd50c2170e + AXON_COMMIT: forcerelay-dev + IBC_CONTRACT_COMMIT: f2bd40fe3d314bb8fa55c828e9832f40a350fa48 CELL_EMITTER_COMMIT: 0a897111b389472a078512815d293703910c25d5 strategy: fail-fast: false 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/axon.rs b/tools/ibc-test/src/framework/utils/axon.rs index 092865feb..8bbf6fce3 100644 --- a/tools/ibc-test/src/framework/utils/axon.rs +++ b/tools/ibc-test/src/framework/utils/axon.rs @@ -258,7 +258,7 @@ pub(crate) fn add_axon_devnet_relayer_wallet( prefix.to_string() }; let private_key = { - let data = hex::decode("37aa0f893d05914a4def0460c0a984d3611546cfb26924d7a7ca6e0db9950a2d") + let data = hex::decode("ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80") .unwrap(); SecretKey::from_slice(&data).unwrap() }; diff --git a/tools/ibc-test/src/framework/utils/common.rs b/tools/ibc-test/src/framework/utils/common.rs index 8784a378a..4533d5f18 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) + std::fs::create_dir_all(&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..17da2ae23 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::rc::Rc; 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: Rc::new(RefCell::new(None)), }) } diff --git a/tools/test-framework/src/types/config.rs b/tools/test-framework/src/types/config.rs index 4ef22f5a0..a11094a64 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, rc::Rc}; /** 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: Rc>>, +} + +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"); + } + } }