From 121540a14717604b1b250a2c6518a56e3bf52674 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Thu, 19 Sep 2024 11:35:11 +0800 Subject: [PATCH] Integration Test: wait rpc ready before test logic Signed-off-by: Eval EXEC --- test/src/miner.rs | 14 ++++++++++++++ test/src/setup.rs | 2 +- test/src/spec/dao.rs | 24 +++++++++++++++--------- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/test/src/miner.rs b/test/src/miner.rs index 03d51b11..1515a9a2 100644 --- a/test/src/miner.rs +++ b/test/src/miner.rs @@ -40,6 +40,20 @@ impl Miner { } } + pub fn wait_rpc_ready(&self) { + let header = self.rpc.lock().unwrap().get_tip_header(); + let now = std::time::Instant::now(); + while now.elapsed().as_secs() < 60 { + if header.is_ok() { + log::info!("rpc is ready"); + return; + } + log::info!("waiting rpc ready..."); + thread::sleep(Duration::from_secs(1)); + } + panic!("rpc not ready") + } + pub fn generate_block(&self) -> H256 { self.rpc .lock() diff --git a/test/src/setup.rs b/test/src/setup.rs index 3a2aaba3..64f78f84 100644 --- a/test/src/setup.rs +++ b/test/src/setup.rs @@ -58,7 +58,7 @@ impl Setup { let ckb_child_process = ckb_cmd .env("RUST_BACKTRACE", "full") .stdin(Stdio::null()) - .stdout(Stdio::null()) + .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) .spawn() .expect("Run `ckb run` failed"); diff --git a/test/src/spec/dao.rs b/test/src/spec/dao.rs index 180802ee..6931550b 100644 --- a/test/src/spec/dao.rs +++ b/test/src/spec/dao.rs @@ -9,8 +9,16 @@ const LOCK_PERIOD_EPOCHES: u64 = 180; pub struct DaoPrepareOne; +fn generate_lock_period_epochs(setup: &mut Setup) { + (0..LOCK_PERIOD_EPOCHES).for_each(|i| { + setup.miner().generate_epochs(1, EPOCH_LENGTH); + }); +} + impl Spec for DaoPrepareOne { fn run(&self, setup: &mut Setup) { + setup.miner().wait_rpc_ready(); + let privkey_path = setup.miner().privkey_path().to_string(); assert_eq!(deposited_capacity(setup), 0); assert_eq!(prepared_capacity(setup), 0); @@ -37,9 +45,7 @@ impl Spec for DaoPrepareOne { assert!(output.contains("Immature")); // Drive the chain until since mature and then withdraw - setup - .miner() - .generate_epochs(LOCK_PERIOD_EPOCHES, EPOCH_LENGTH); + generate_lock_period_epochs(setup); let out_points = vec![new_out_point(prepare_tx_hash, 0)]; let _withdraw_tx_hash = withdraw(setup, &out_points); assert_eq!(deposited_capacity(setup), 0); @@ -61,6 +67,8 @@ pub struct DaoPrepareMultiple; impl Spec for DaoPrepareMultiple { fn run(&self, setup: &mut Setup) { + setup.miner().wait_rpc_ready(); + let privkey_path = setup.miner().privkey_path().to_string(); assert_eq!(deposited_capacity(setup), 0); assert_eq!(prepared_capacity(setup), 0); @@ -87,9 +95,7 @@ impl Spec for DaoPrepareMultiple { assert!(output.contains("Immature")); // Drive the chain until since mature and then withdraw - setup - .miner() - .generate_epochs(LOCK_PERIOD_EPOCHES, EPOCH_LENGTH); + generate_lock_period_epochs(setup); let out_points = (0..shannons.len()) .map(|i| new_out_point(&prepare_tx_hash, i)) .collect::>(); @@ -114,6 +120,8 @@ pub struct DaoWithdrawMultiple; impl Spec for DaoWithdrawMultiple { #[allow(clippy::needless_collect)] fn run(&self, setup: &mut Setup) { + setup.miner().wait_rpc_ready(); + assert_eq!(deposited_capacity(setup), 0); assert_eq!(prepared_capacity(setup), 0); @@ -133,9 +141,7 @@ impl Spec for DaoWithdrawMultiple { assert_eq!(prepared_capacity(setup), 40_010_336_948_502); // Drive the chain until since mature and then withdraw - setup - .miner() - .generate_epochs(LOCK_PERIOD_EPOCHES, EPOCH_LENGTH); + generate_lock_period_epochs(setup); let out_points = prepare_tx_hashes .into_iter() .map(|hash| new_out_point(hash, 0))