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 fc061ae
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
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
9 changes: 4 additions & 5 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)
.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::sync::Arc;
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: Arc::new(RefCell::new(None)),

Check failure on line 70 in tools/test-framework/src/bootstrap/init.rs

View workflow job for this annotation

GitHub Actions / clippy-all-features

usage of an `Arc` that is not `Send` or `Sync`

error: usage of an `Arc` that is not `Send` or `Sync` --> tools/test-framework/src/bootstrap/init.rs:70:24 | 70 | extra_process: Arc::new(RefCell::new(None)), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the trait `Sync` is not implemented for `RefCell<Option<Child>>` = note: required for `Arc<RefCell<Option<Child>>>` to implement `Send` and `Sync` = help: consider using an `Rc` instead or wrapping the inner type with a `Mutex` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync = note: `-D clippy::arc-with-non-send-sync` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::arc_with_non_send_sync)]`

Check failure on line 70 in tools/test-framework/src/bootstrap/init.rs

View workflow job for this annotation

GitHub Actions / clippy-all-features

usage of an `Arc` that is not `Send` or `Sync`

error: usage of an `Arc` that is not `Send` or `Sync` --> tools/test-framework/src/bootstrap/init.rs:70:24 | 70 | extra_process: Arc::new(RefCell::new(None)), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the trait `Sync` is not implemented for `RefCell<Option<Child>>` = note: required for `Arc<RefCell<Option<Child>>>` to implement `Send` and `Sync` = help: consider using an `Rc` instead or wrapping the inner type with a `Mutex` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync = note: `-D clippy::arc-with-non-send-sync` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::arc_with_non_send_sync)]`

Check failure on line 70 in tools/test-framework/src/bootstrap/init.rs

View workflow job for this annotation

GitHub Actions / clippy-no-default-features

usage of an `Arc` that is not `Send` or `Sync`

error: usage of an `Arc` that is not `Send` or `Sync` --> tools/test-framework/src/bootstrap/init.rs:70:24 | 70 | extra_process: Arc::new(RefCell::new(None)), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the trait `Sync` is not implemented for `RefCell<Option<Child>>` = note: required for `Arc<RefCell<Option<Child>>>` to implement `Send` and `Sync` = help: consider using an `Rc` instead or wrapping the inner type with a `Mutex` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync = note: `-D clippy::arc-with-non-send-sync` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::arc_with_non_send_sync)]`

Check failure on line 70 in tools/test-framework/src/bootstrap/init.rs

View workflow job for this annotation

GitHub Actions / clippy-no-default-features

usage of an `Arc` that is not `Send` or `Sync`

error: usage of an `Arc` that is not `Send` or `Sync` --> tools/test-framework/src/bootstrap/init.rs:70:24 | 70 | extra_process: Arc::new(RefCell::new(None)), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the trait `Sync` is not implemented for `RefCell<Option<Child>>` = note: required for `Arc<RefCell<Option<Child>>>` to implement `Send` and `Sync` = help: consider using an `Rc` instead or wrapping the inner type with a `Mutex` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync = note: `-D clippy::arc-with-non-send-sync` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::arc_with_non_send_sync)]`
})
}

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, sync::Arc};

/**
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: Arc<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 fc061ae

Please sign in to comment.