Skip to content

Commit

Permalink
chore: add header sync console print
Browse files Browse the repository at this point in the history
  • Loading branch information
liyukun committed Dec 21, 2023
1 parent c7683da commit 5a605e7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
29 changes: 27 additions & 2 deletions tools/ibc-test/src/framework/utils/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ pub fn transfer_port_id(chain_type: ChainType) -> PortId {
}
}

pub fn prepare_cell_emitter(axon_port: u16, ckb_port: u16) -> Result<Child, Error> {
pub fn prepare_cell_emitter(
axon_port: u16,
ckb_port: u16,
) -> Result<(Child, std::sync::mpsc::Sender<()>), Error> {
let listen_port = rngs::OsRng.gen_range(9000..10000);
let private_path = std::env::current_dir()
.unwrap()
Expand Down Expand Up @@ -96,5 +99,27 @@ pub fn prepare_cell_emitter(axon_port: u16, ckb_port: u16) -> Result<Child, Erro
.arg(private_path)
.spawn()
.map_err(|err| eyre!("failed to start emitter: {err}"))?;
Ok(emitter_thread)
// check header sync progress
let (tx, rx) = std::sync::mpsc::channel();
std::thread::spawn(move || loop {
std::thread::sleep(Duration::from_secs(10));
let output = Command::new("curl")
.arg("-H")
.arg("content-type: application/json")
.arg("-d")
.arg("{\"id\": 2, \"jsonrpc\": \"2.0\", \"method\": \"info\", \"params\": [] }")
.arg(format!("http://127.0.0.1:{listen_port}"))
.output()
.unwrap();
let log = if output.status.success() {
output.stdout
} else {
output.stderr
};
println!("\n[CellEmitter] {}", String::from_utf8(log).unwrap());
if rx.try_recv().is_ok() {
return;
}
});
Ok((emitter_thread, tx))
}
12 changes: 5 additions & 7 deletions 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::{cell::RefCell, path::PathBuf, process::Child, rc::Rc};
use std::{cell::RefCell, path::PathBuf, process::Child, rc::Rc, sync::mpsc::Sender};

/**
The test config to be passed to each test case. Currently this is loaded
Expand Down Expand Up @@ -59,19 +59,17 @@ pub struct TestConfig {

pub bootstrap_with_random_ids: bool,

pub extra_process: Rc<RefCell<Option<Child>>>,
pub extra_process: Rc<RefCell<Option<(Child, Sender<()>)>>>,
}

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");
let (ref mut child, handler) = process.as_mut().unwrap();
child.kill().unwrap();
handler.send(()).unwrap();
}
}
}

0 comments on commit 5a605e7

Please sign in to comment.