Skip to content

Commit

Permalink
chore: follow emitter sub process
Browse files Browse the repository at this point in the history
  • Loading branch information
liyukun committed Dec 20, 2023
1 parent 73401ec commit 0a4c9ea
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ibc-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions tools/ibc-test/src/framework/binary/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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..........");
Expand Down
2 changes: 1 addition & 1 deletion tools/ibc-test/src/framework/utils/axon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand Down
11 changes: 5 additions & 6 deletions tools/ibc-test/src/framework/utils/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<Child, Error> {
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")
Expand All @@ -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)
}
3 changes: 3 additions & 0 deletions tools/test-framework/src/bootstrap/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -65,6 +67,7 @@ pub fn init_test() -> Result<TestConfig, Error> {
account_prefixes,
hang_on_fail,
bootstrap_with_random_ids: false,
extra_process: Rc::new(RefCell::new(None)),
})
}

Expand Down
18 changes: 17 additions & 1 deletion tools/test-framework/src/types/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -58,4 +58,20 @@ pub struct TestConfig {
pub hang_on_fail: bool,

pub bootstrap_with_random_ids: bool,

pub extra_process: Rc<RefCell<Option<Child>>>,
}

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");
}
}
}

0 comments on commit 0a4c9ea

Please sign in to comment.