From 3a0bb1db528092578244e47c07430ca810414247 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Mon, 24 Aug 2020 13:45:42 -0700 Subject: [PATCH] fix(test): fix test_4_20_kill1 Fixes #3141 Test plan --------- test_4_20_kill1 --- Cargo.lock | 1 + Cargo.toml | 1 + test-utils/testlib/src/node/process_node.rs | 23 ++++++++++++++++++++- tests/test_rejoin.rs | 2 ++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 20651aa6c84..abec6744380 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2791,6 +2791,7 @@ dependencies = [ "futures", "lazy_static", "log", + "near-actix-utils", "near-chain-configs", "near-crypto", "near-jsonrpc", diff --git a/Cargo.toml b/Cargo.toml index c191e1d735d..cf6b90e2ca8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,6 +59,7 @@ serde_json = "1" futures = "0.3" near-logger-utils = { path = "./test-utils/logger" } +near-actix-utils = { path = "./utils/actix" } near-chain-configs = { path = "./core/chain-configs" } near-crypto = { path = "./core/crypto" } near-primitives = { path = "./core/primitives" } diff --git a/test-utils/testlib/src/node/process_node.rs b/test-utils/testlib/src/node/process_node.rs index a745a8279a9..534c4f7debb 100644 --- a/test-utils/testlib/src/node/process_node.rs +++ b/test-utils/testlib/src/node/process_node.rs @@ -15,6 +15,10 @@ use neard::config::NearConfig; use crate::node::Node; use crate::user::rpc_user::RpcUser; use crate::user::User; +use actix::{Actor, System}; +use futures::{FutureExt, TryFutureExt}; +use near_jsonrpc_client::new_client; +use near_network::test_utils::WaitOrTimeout; pub enum ProcessNodeState { Stopped, @@ -46,7 +50,24 @@ impl Node for ProcessNode { let child = self.get_start_node_command().spawn().expect("start node command failed"); self.state = ProcessNodeState::Running(child); - thread::sleep(Duration::from_secs(3)); + let addr = self.config.rpc_config.addr.clone(); + + System::run(|| { + WaitOrTimeout::new( + Box::new(move |_| { + actix::spawn( + new_client(&format!("http://{}", addr)) + .status() + .map_ok(|_| System::current().stop()) + .map(drop), + ) + }), + 500, + 10000, + ) + .start(); + }) + .unwrap(); } ProcessNodeState::Running(_) => panic!("Node is already running"), } diff --git a/tests/test_rejoin.rs b/tests/test_rejoin.rs index 95cbccab2fe..ce7a0cd21d2 100644 --- a/tests/test_rejoin.rs +++ b/tests/test_rejoin.rs @@ -53,6 +53,8 @@ mod test { fn test_kill_1(num_nodes: usize, num_trials: usize, two_shards: bool, test_prefix: &str) { warmup(); + near_actix_utils::init_stop_on_panic(); + // Start all nodes, crash node#2, proceed, restart node #2 but crash node #3 let crash1 = 2; let crash2 = 3;