diff --git a/chain/client/tests/bug_repros.rs b/chain/client/tests/bug_repros.rs index 1eadd70c8c1..fdede57229e 100644 --- a/chain/client/tests/bug_repros.rs +++ b/chain/client/tests/bug_repros.rs @@ -9,7 +9,7 @@ use actix::{Addr, System}; use futures::FutureExt; use rand::{thread_rng, Rng}; -use near_actix_test_utils::run_actix_until_stop; +use near_actix_test_utils::run_actix; use near_chain::test_utils::account_id_to_shard_id; use near_client::test_utils::setup_mock_all_validators; use near_client::{ClientActor, GetBlock, ViewClientActor}; @@ -24,7 +24,7 @@ use near_primitives::transaction::SignedTransaction; fn repro_1183() { let validator_groups = 2; init_test_logger(); - run_actix_until_stop(async { + run_actix(async { let connectors: Arc, Addr)>>> = Arc::new(RwLock::new(vec![])); @@ -146,7 +146,7 @@ fn test_sync_from_achival_node() { let blocks = Arc::new(RwLock::new(HashMap::new())); let epoch_length = 4; - run_actix_until_stop(async move { + run_actix(async move { let network_mock: Arc< RwLock (NetworkResponses, bool)>>, > = Arc::new(RwLock::new(Box::new(|_: String, _: &NetworkRequests| { @@ -242,7 +242,7 @@ fn test_long_gap_between_blocks() { let epoch_length = 1000; let target_height = 600; - run_actix_until_stop(async move { + run_actix(async move { let network_mock: Arc< RwLock (NetworkResponses, bool)>>, > = Arc::new(RwLock::new(Box::new(|_: String, _: &NetworkRequests| { diff --git a/chain/client/tests/catching_up.rs b/chain/client/tests/catching_up.rs index d5ff0627a2d..ad930943e6b 100644 --- a/chain/client/tests/catching_up.rs +++ b/chain/client/tests/catching_up.rs @@ -9,7 +9,7 @@ mod tests { use borsh::{BorshDeserialize, BorshSerialize}; use futures::{future, FutureExt}; - use near_actix_test_utils::run_actix_until_stop; + use near_actix_test_utils::run_actix; use near_chain::test_utils::account_id_to_shard_id; use near_chain_configs::TEST_STATE_SYNC_TIMEOUT; use near_client::test_utils::setup_mock_all_validators; @@ -121,7 +121,7 @@ mod tests { fn test_catchup_receipts_sync_common(wait_till: u64, send: u64, sync_hold: bool) { let validator_groups = 1; init_integration_logger(); - run_actix_until_stop(async move { + run_actix(async move { let connectors: Arc, Addr)>>> = Arc::new(RwLock::new(vec![])); @@ -400,7 +400,7 @@ mod tests { fn test_catchup_random_single_part_sync_common(skip_15: bool, non_zero: bool, height: u64) { let validator_groups = 2; init_integration_logger(); - run_actix_until_stop(async move { + run_actix(async move { let connectors: Arc, Addr)>>> = Arc::new(RwLock::new(vec![])); @@ -611,7 +611,7 @@ mod tests { fn test_catchup_sanity_blocks_produced() { let validator_groups = 2; init_integration_logger(); - run_actix_until_stop(async move { + run_actix(async move { let connectors: Arc, Addr)>>> = Arc::new(RwLock::new(vec![])); @@ -692,7 +692,7 @@ mod tests { fn test_chunk_grieving() { let validator_groups = 1; init_integration_logger(); - run_actix_until_stop(async move { + run_actix(async move { let connectors: Arc, Addr)>>> = Arc::new(RwLock::new(vec![])); @@ -862,7 +862,7 @@ mod tests { ) { let validator_groups = 1; init_integration_logger(); - run_actix_until_stop(async move { + run_actix(async move { let connectors: Arc, Addr)>>> = Arc::new(RwLock::new(vec![])); diff --git a/chain/client/tests/chunks_management.rs b/chain/client/tests/chunks_management.rs index 39abc778d61..aabba7343a0 100644 --- a/chain/client/tests/chunks_management.rs +++ b/chain/client/tests/chunks_management.rs @@ -7,7 +7,7 @@ use actix::{Addr, System}; use futures::{future, FutureExt}; use log::info; -use near_actix_test_utils::{run_actix_until_panic, run_actix_until_stop}; +use near_actix_test_utils::run_actix; use near_chain::ChainGenesis; use near_chunks::{ CHUNK_REQUEST_RETRY_MS, CHUNK_REQUEST_SWITCH_TO_FULL_FETCH_MS, @@ -33,7 +33,7 @@ use testlib::test_helpers::heavy_test; #[test] fn chunks_produced_and_distributed_all_in_all_shards() { heavy_test(|| { - run_actix_until_stop(async { + run_actix(async { chunks_produced_and_distributed_common(1, false, 15 * CHUNK_REQUEST_RETRY_MS); }); }); @@ -42,7 +42,7 @@ fn chunks_produced_and_distributed_all_in_all_shards() { #[test] fn chunks_produced_and_distributed_2_vals_per_shard() { heavy_test(|| { - run_actix_until_stop(async { + run_actix(async { chunks_produced_and_distributed_common(2, false, 15 * CHUNK_REQUEST_RETRY_MS); }); }); @@ -51,7 +51,7 @@ fn chunks_produced_and_distributed_2_vals_per_shard() { #[test] fn chunks_produced_and_distributed_one_val_per_shard() { heavy_test(|| { - run_actix_until_stop(async { + run_actix(async { chunks_produced_and_distributed_common(4, false, 15 * CHUNK_REQUEST_RETRY_MS); }); }); @@ -65,7 +65,7 @@ fn chunks_produced_and_distributed_one_val_per_shard() { #[test] fn chunks_recovered_from_others() { heavy_test(|| { - run_actix_until_stop(async { + run_actix(async { chunks_produced_and_distributed_common(2, true, 4 * CHUNK_REQUEST_SWITCH_TO_OTHERS_MS); }); }); @@ -79,7 +79,7 @@ fn chunks_recovered_from_others() { #[should_panic] fn chunks_recovered_from_full_timeout_too_short() { heavy_test(|| { - run_actix_until_panic(async { + run_actix(async { chunks_produced_and_distributed_common(4, true, 2 * CHUNK_REQUEST_SWITCH_TO_OTHERS_MS); }); }); @@ -90,7 +90,7 @@ fn chunks_recovered_from_full_timeout_too_short() { #[test] fn chunks_recovered_from_full() { heavy_test(|| { - run_actix_until_stop(async { + run_actix(async { chunks_produced_and_distributed_common( 4, true, diff --git a/chain/client/tests/consensus.rs b/chain/client/tests/consensus.rs index 5398f667086..9317b6bb5c7 100644 --- a/chain/client/tests/consensus.rs +++ b/chain/client/tests/consensus.rs @@ -7,7 +7,7 @@ mod tests { use actix::{Addr, System}; use rand::{thread_rng, Rng}; - use near_actix_test_utils::run_actix_until_stop; + use near_actix_test_utils::run_actix; use near_chain::Block; use near_client::test_utils::setup_mock_all_validators; use near_client::{ClientActor, ViewClientActor}; @@ -27,7 +27,7 @@ mod tests { const HEIGHT_GOAL: u64 = 120; - run_actix_until_stop(async move { + run_actix(async move { let connectors: Arc, Addr)>>> = Arc::new(RwLock::new(vec![])); let connectors1 = connectors.clone(); diff --git a/chain/client/tests/cross_shard_tx.rs b/chain/client/tests/cross_shard_tx.rs index 47ae0e345ef..98a1e6e1756 100644 --- a/chain/client/tests/cross_shard_tx.rs +++ b/chain/client/tests/cross_shard_tx.rs @@ -4,7 +4,7 @@ use std::sync::{Arc, RwLock}; use actix::{Addr, System}; use futures::{future, FutureExt}; -use near_actix_test_utils::run_actix_until_stop; +use near_actix_test_utils::run_actix; use near_client::test_utils::setup_mock_all_validators; use near_client::{ClientActor, Query, ViewClientActor}; use near_logger_utils::init_integration_logger; @@ -18,7 +18,7 @@ fn test_keyvalue_runtime_balances() { let validator_groups = 2; let successful_queries = Arc::new(AtomicUsize::new(0)); init_integration_logger(); - run_actix_until_stop(async move { + run_actix(async move { let connectors: Arc, Addr)>>> = Arc::new(RwLock::new(vec![])); @@ -86,7 +86,7 @@ mod tests { use actix::{Addr, MailboxError, System}; use futures::{future, FutureExt}; - use near_actix_test_utils::run_actix_until_stop; + use near_actix_test_utils::run_actix; use near_chain::test_utils::account_id_to_shard_id; use near_client::test_utils::{setup_mock_all_validators, BlockStats}; use near_client::{ClientActor, Query, ViewClientActor}; @@ -394,7 +394,7 @@ mod tests { ) { let validator_groups = 4; init_integration_logger(); - run_actix_until_stop(async move { + run_actix(async move { let connectors: Arc, Addr)>>> = Arc::new(RwLock::new(vec![])); diff --git a/chain/client/tests/process_blocks.rs b/chain/client/tests/process_blocks.rs index 056b3136e52..3f3e0032d74 100644 --- a/chain/client/tests/process_blocks.rs +++ b/chain/client/tests/process_blocks.rs @@ -9,7 +9,7 @@ use actix::System; use futures::{future, FutureExt}; use num_rational::Rational; -use near_actix_test_utils::run_actix_until_stop; +use near_actix_test_utils::run_actix; use near_chain::chain::NUM_EPOCHS_TO_KEEP_STORE_DATA; use near_chain::types::LatestKnown; use near_chain::validate::validate_chunk_with_chunk_extra; @@ -170,7 +170,7 @@ fn prepare_env_with_congestion( #[test] fn produce_two_blocks() { init_test_logger(); - run_actix_until_stop(async { + run_actix(async { let count = Arc::new(AtomicUsize::new(0)); setup_mock( vec!["test"], @@ -198,7 +198,7 @@ fn produce_two_blocks() { fn produce_blocks_with_tx() { let mut encoded_chunks: Vec = vec![]; init_test_logger(); - run_actix_until_stop(async { + run_actix(async { let (client, view_client) = setup_mock( vec!["test"], "test", @@ -263,7 +263,7 @@ fn produce_blocks_with_tx() { #[test] fn receive_network_block() { init_test_logger(); - run_actix_until_stop(async { + run_actix(async { // The first header announce will be when the block is received. We don't immediately endorse // it. The second header announce will happen with the endorsement a little later. let first_header_announce = Arc::new(RwLock::new(true)); @@ -330,7 +330,7 @@ fn produce_block_with_approvals() { let validators = vec![ "test1", "test2", "test3", "test4", "test5", "test6", "test7", "test8", "test9", "test10", ]; - run_actix_until_stop(async { + run_actix(async { let (client, view_client) = setup_mock( validators.clone(), "test1", @@ -424,7 +424,7 @@ fn produce_block_with_approvals_arrived_early() { let key_pairs = vec![PeerInfo::random(), PeerInfo::random(), PeerInfo::random(), PeerInfo::random()]; let block_holder: Arc>> = Arc::new(RwLock::new(None)); - run_actix_until_stop(async move { + run_actix(async move { let mut approval_counter = 0; let network_mock: Arc< RwLock (NetworkResponses, bool)>>, @@ -495,7 +495,7 @@ fn produce_block_with_approvals_arrived_early() { /// and that the node bans the peer for invalid block header. fn invalid_blocks_common(is_requested: bool) { init_test_logger(); - run_actix_until_stop(async move { + run_actix(async move { let mut ban_counter = 0; let (client, view_client) = setup_mock( vec!["test"], @@ -638,7 +638,7 @@ fn ban_peer_for_invalid_block_common(mode: InvalidBlockMode) { let validators = vec![vec!["test1", "test2", "test3", "test4"]]; let key_pairs = vec![PeerInfo::random(), PeerInfo::random(), PeerInfo::random(), PeerInfo::random()]; - run_actix_until_stop(async move { + run_actix(async move { let mut ban_counter = 0; let network_mock: Arc< RwLock (NetworkResponses, bool)>>, @@ -776,7 +776,7 @@ fn test_ban_peer_for_ill_formed_block() { #[test] fn skip_block_production() { init_test_logger(); - run_actix_until_stop(async { + run_actix(async { setup_mock( vec!["test1", "test2"], "test2", @@ -802,7 +802,7 @@ fn skip_block_production() { #[test] fn client_sync_headers() { init_test_logger(); - run_actix_until_stop(async { + run_actix(async { let peer_info1 = PeerInfo::random(); let peer_info2 = peer_info1.clone(); let (client, _) = setup_mock( diff --git a/chain/client/tests/query_client.rs b/chain/client/tests/query_client.rs index 61a1efe1756..48b8c617658 100644 --- a/chain/client/tests/query_client.rs +++ b/chain/client/tests/query_client.rs @@ -2,7 +2,7 @@ use actix::System; use futures::{future, FutureExt}; use chrono::Utc; -use near_actix_test_utils::run_actix_until_stop; +use near_actix_test_utils::run_actix; use near_client::test_utils::{setup, setup_no_network}; use near_client::{ GetBlock, GetBlockWithMerkleTree, GetExecutionOutcomesForBlock, Query, Status, TxStatus, @@ -27,7 +27,7 @@ use std::time::Duration; #[test] fn query_client() { init_test_logger(); - run_actix_until_stop(async { + run_actix(async { let (_, view_client) = setup_no_network(vec!["test"], "other", true, true); actix::spawn( view_client @@ -52,7 +52,7 @@ fn query_client() { #[test] fn query_status_not_crash() { init_test_logger(); - run_actix_until_stop(async { + run_actix(async { let (client, view_client) = setup_no_network(vec!["test"], "other", true, false); let signer = InMemoryValidatorSigner::from_seed("test", KeyType::ED25519, "test"); actix::spawn(view_client.send(GetBlockWithMerkleTree::latest()).then(move |res| { @@ -107,7 +107,7 @@ fn query_status_not_crash() { #[test] fn test_execution_outcome_for_chunk() { init_test_logger(); - run_actix_until_stop(async { + run_actix(async { let (client, view_client) = setup_no_network(vec!["test"], "test", true, false); let signer = InMemorySigner::from_seed("test", KeyType::ED25519, "test"); @@ -171,7 +171,7 @@ fn test_execution_outcome_for_chunk() { #[test] fn test_state_request() { - run_actix_until_stop(async { + run_actix(async { let (_, _, view_client) = setup( vec![vec!["test"]], 1, diff --git a/chain/jsonrpc/test-utils/src/lib.rs b/chain/jsonrpc/test-utils/src/lib.rs index 072a02025d5..bb657c3ec4f 100644 --- a/chain/jsonrpc/test-utils/src/lib.rs +++ b/chain/jsonrpc/test-utils/src/lib.rs @@ -50,7 +50,7 @@ macro_rules! test_with_client { ($node_type:expr, $client:ident, $block:expr) => { init_test_logger(); - run_actix_until_stop(|| { + run_actix(|| { let (_view_client_addr, addr) = test_utils::start_all($node_type); let $client = new_client(&format!("http://{}", addr)); diff --git a/chain/jsonrpc/tests/http_query.rs b/chain/jsonrpc/tests/http_query.rs index 7d2bdf5deb2..c85a7e9cbf0 100644 --- a/chain/jsonrpc/tests/http_query.rs +++ b/chain/jsonrpc/tests/http_query.rs @@ -1,7 +1,7 @@ use actix::System; use futures::{future, FutureExt}; -use near_actix_test_utils::run_actix_until_stop; +use near_actix_test_utils::run_actix; use near_jsonrpc::client::new_http_client; use near_logger_utils::init_test_logger; @@ -12,7 +12,7 @@ pub mod test_utils; fn test_status() { init_test_logger(); - run_actix_until_stop(async { + run_actix(async { let (_view_client_addr, addr) = test_utils::start_all(test_utils::NodeType::NonValidator); let client = new_http_client(&format!("http://{}", addr)); diff --git a/chain/jsonrpc/tests/rpc_query.rs b/chain/jsonrpc/tests/rpc_query.rs index 694e92da10d..b52653c3722 100644 --- a/chain/jsonrpc/tests/rpc_query.rs +++ b/chain/jsonrpc/tests/rpc_query.rs @@ -4,7 +4,7 @@ use actix::{Actor, System}; use futures::{future, FutureExt}; use serde_json::json; -use near_actix_test_utils::run_actix_until_stop; +use near_actix_test_utils::run_actix; use near_crypto::{KeyType, PublicKey, Signature}; use near_jsonrpc::client::new_client; use near_jsonrpc_client::ChunkId; @@ -383,7 +383,7 @@ fn test_status() { fn test_status_fail() { init_test_logger(); - run_actix_until_stop(async { + run_actix(async { let (_, addr) = test_utils::start_all(test_utils::NodeType::NonValidator); let client = new_client(&format!("http://{}", addr)); @@ -408,7 +408,7 @@ fn test_status_fail() { fn test_health_fail() { init_test_logger(); - run_actix_until_stop(async { + run_actix(async { let client = new_client(&"http://127.0.0.1:12322/health"); actix::spawn(client.health().then(|res| { assert!(res.is_err()); @@ -423,7 +423,7 @@ fn test_health_fail() { fn test_health_fail_no_blocks() { init_test_logger(); - run_actix_until_stop(async { + run_actix(async { let (_, addr) = test_utils::start_all(test_utils::NodeType::NonValidator); let client = new_client(&format!("http://{}", addr)); diff --git a/chain/jsonrpc/tests/rpc_transactions.rs b/chain/jsonrpc/tests/rpc_transactions.rs index 78f4157d9fe..e8d6023030d 100644 --- a/chain/jsonrpc/tests/rpc_transactions.rs +++ b/chain/jsonrpc/tests/rpc_transactions.rs @@ -4,7 +4,7 @@ use actix::{Actor, System}; use borsh::BorshSerialize; use futures::{future, FutureExt, TryFutureExt}; -use near_actix_test_utils::run_actix_until_stop; +use near_actix_test_utils::run_actix; use near_crypto::{InMemorySigner, KeyType}; use near_jsonrpc::client::new_client; use near_logger_utils::{init_integration_logger, init_test_logger}; @@ -23,7 +23,7 @@ pub mod test_utils; fn test_send_tx_async() { init_test_logger(); - run_actix_until_stop(async { + run_actix(async { let (_, addr) = test_utils::start_all(test_utils::NodeType::Validator); let client = new_client(&format!("http://{}", addr.clone())); @@ -101,7 +101,7 @@ fn test_send_tx_commit() { #[test] fn test_expired_tx() { init_integration_logger(); - run_actix_until_stop(async { + run_actix(async { let (_, addr) = test_utils::start_all_with_validity_period_and_no_epoch_sync( test_utils::NodeType::Validator, 1, diff --git a/chain/jsonrpc/tests/test_utils/mod.rs b/chain/jsonrpc/tests/test_utils/mod.rs index 695c703a779..a6e09e4090d 100644 --- a/chain/jsonrpc/tests/test_utils/mod.rs +++ b/chain/jsonrpc/tests/test_utils/mod.rs @@ -54,7 +54,7 @@ macro_rules! test_with_client { ($node_type:expr, $client:ident, $block:expr) => { init_test_logger(); - near_actix_test_utils::run_actix_until_stop(async { + near_actix_test_utils::run_actix(async { let (_view_client_addr, addr) = test_utils::start_all($node_type); let $client = new_client(&format!("http://{}", addr)); diff --git a/chain/network/src/test_utils.rs b/chain/network/src/test_utils.rs index 480dee20e62..eb649868dd8 100644 --- a/chain/network/src/test_utils.rs +++ b/chain/network/src/test_utils.rs @@ -123,7 +123,7 @@ pub fn wait_or_panic(max_wait_ms: u64) { /// use near_network::test_utils::WaitOrTimeout; /// use std::time::{Instant, Duration}; /// -/// near_actix_test_utils::run_actix_until_stop(async { +/// near_actix_test_utils::run_actix(async { /// let start = Instant::now(); /// WaitOrTimeout::new( /// Box::new(move |ctx| { diff --git a/chain/network/tests/infinite_loop.rs b/chain/network/tests/infinite_loop.rs index 9040599e1fe..8e9626a07dc 100644 --- a/chain/network/tests/infinite_loop.rs +++ b/chain/network/tests/infinite_loop.rs @@ -6,7 +6,7 @@ use actix::actors::mocker::Mocker; use actix::{Actor, System}; use futures::{future, FutureExt}; -use near_actix_test_utils::run_actix_until_stop; +use near_actix_test_utils::run_actix; use near_client::ClientActor; use near_logger_utils::init_integration_logger; use near_network::test_utils::{convert_boot_nodes, open_port, GetInfo, WaitOrTimeout}; @@ -72,7 +72,7 @@ type ViewClientMock = Mocker; #[test] fn test_infinite_loop() { init_integration_logger(); - run_actix_until_stop(async { + run_actix(async { let (port1, port2) = (open_port(), open_port()); let (pm1, peer_id1, counter1) = make_peer_manager("test1", port1, vec![], 10); let (pm2, peer_id2, counter2) = diff --git a/chain/network/tests/peer_handshake.rs b/chain/network/tests/peer_handshake.rs index 4439d4a9257..82b0aedc096 100644 --- a/chain/network/tests/peer_handshake.rs +++ b/chain/network/tests/peer_handshake.rs @@ -10,7 +10,7 @@ use actix::System; use actix::{Actor, Arbiter}; use futures::{future, FutureExt}; -use near_actix_test_utils::run_actix_until_stop; +use near_actix_test_utils::run_actix; use near_client::{ClientActor, ViewClientActor}; use near_logger_utils::init_test_logger; use near_network::test_utils::{convert_boot_nodes, open_port, GetInfo, StopSignal, WaitOrTimeout}; @@ -59,7 +59,7 @@ fn make_peer_manager( fn peer_handshake() { init_test_logger(); - run_actix_until_stop(async { + run_actix(async { let (port1, port2) = (open_port(), open_port()); let pm1 = make_peer_manager("test1", port1, vec![("test2", port2)], 10).start(); let _pm2 = make_peer_manager("test2", port2, vec![("test1", port1)], 10).start(); @@ -84,7 +84,7 @@ fn peer_handshake() { fn peers_connect_all() { init_test_logger(); - run_actix_until_stop(async { + run_actix(async { let port = open_port(); let _pm = make_peer_manager("test", port, vec![], 10).start(); let mut peers = vec![]; @@ -127,7 +127,7 @@ fn peers_connect_all() { fn peer_recover() { init_test_logger(); - run_actix_until_stop(async { + run_actix(async { let port0 = open_port(); let pm0 = Arc::new(make_peer_manager("test0", port0, vec![], 2).start()); let _pm1 = make_peer_manager("test1", open_port(), vec![("test0", port0)], 1).start(); @@ -227,7 +227,7 @@ fn connection_spam_security_test() { let vec: Arc>> = Arc::new(RwLock::new(Vec::new())); let vec2: Arc>> = vec.clone(); - run_actix_until_stop(async move { + run_actix(async move { let arbiter = Arbiter::new(); let port = open_port(); diff --git a/chain/network/tests/runner/mod.rs b/chain/network/tests/runner/mod.rs index 5fa371f1835..846343fd565 100644 --- a/chain/network/tests/runner/mod.rs +++ b/chain/network/tests/runner/mod.rs @@ -8,7 +8,7 @@ use actix::{Actor, Addr, AsyncContext, Context, Handler, Message, System}; use chrono::{DateTime, Utc}; use futures::{future, FutureExt, TryFutureExt}; -use near_actix_test_utils::run_actix_until_stop; +use near_actix_test_utils::run_actix; use near_chain::test_utils::KeyValueRuntime; use near_chain::ChainGenesis; use near_chain_configs::ClientConfig; @@ -601,7 +601,7 @@ impl Runner { /// Use to start running the test. /// It will fail if it doesn't solve all actions. pub fn start_test(runner: Runner) { - run_actix_until_stop(async { + run_actix(async { runner.start(); }) } diff --git a/chain/network/tests/stress_network.rs b/chain/network/tests/stress_network.rs index 31006f5c997..675a5586b2e 100644 --- a/chain/network/tests/stress_network.rs +++ b/chain/network/tests/stress_network.rs @@ -7,7 +7,7 @@ use actix::{Actor, AsyncContext, System}; use futures::FutureExt; use tracing::info; -use near_actix_test_utils::run_actix_until_stop; +use near_actix_test_utils::run_actix; use near_client::{ClientActor, ViewClientActor}; use near_logger_utils::init_test_logger_allow_panic; use near_network::test_utils::{convert_boot_nodes, open_port, GetInfo, StopSignal, WaitOrTimeout}; @@ -68,7 +68,7 @@ fn make_peer_manager(seed: &str, port: u16, boot_nodes: Vec<(&str, u16)>) -> Pee fn stress_test() { init_test_logger_allow_panic(); - run_actix_until_stop(async { + run_actix(async { let num_nodes = 7; let ports: Vec<_> = (0..num_nodes).map(|_| open_port()).collect(); diff --git a/nearcore/tests/node_cluster.rs b/nearcore/tests/node_cluster.rs index 7b11cc7eac2..578b0756542 100644 --- a/nearcore/tests/node_cluster.rs +++ b/nearcore/tests/node_cluster.rs @@ -1,6 +1,6 @@ use futures::future; -use near_actix_test_utils::{run_actix_until_stop, spawn_interruptible}; +use near_actix_test_utils::{run_actix, spawn_interruptible}; use near_client::{ClientActor, ViewClientActor}; use near_primitives::types::{BlockHeight, BlockHeightDelta, NumSeats, NumShards}; use testlib::{start_nodes, test_helpers::heavy_test}; @@ -74,7 +74,7 @@ impl NodeCluster { self.genesis_height.expect("cluster config: [genesis_height] undefined"), ); heavy_test(|| { - run_actix_until_stop(async { + run_actix(async { let (genesis, rpc_addrs, clients) = start_nodes( num_shards, &self.dirs, diff --git a/nearcore/tests/stake_nodes.rs b/nearcore/tests/stake_nodes.rs index e0d79701d32..86fd867e464 100644 --- a/nearcore/tests/stake_nodes.rs +++ b/nearcore/tests/stake_nodes.rs @@ -8,7 +8,7 @@ use futures::{future, FutureExt}; use num_rational::Rational; use rand::Rng; -use near_actix_test_utils::run_actix_until_stop; +use near_actix_test_utils::run_actix; use near_chain_configs::Genesis; use near_client::{ClientActor, GetBlock, Query, Status, ViewClientActor}; use near_crypto::{InMemorySigner, KeyType}; @@ -91,7 +91,7 @@ fn init_test_staking( #[test] fn test_stake_nodes() { heavy_test(|| { - run_actix_until_stop(async move { + run_actix(async move { let num_nodes = 2; let dirs = (0..num_nodes) .map(|i| { @@ -164,7 +164,7 @@ fn test_stake_nodes() { #[test] fn test_validator_kickout() { heavy_test(|| { - run_actix_until_stop(async move { + run_actix(async move { let num_nodes = 4; let dirs = (0..num_nodes) .map(|i| { @@ -311,7 +311,7 @@ fn test_validator_kickout() { #[test] fn test_validator_join() { heavy_test(|| { - run_actix_until_stop(async move { + run_actix(async move { let num_nodes = 4; let dirs = (0..num_nodes) .map(|i| { @@ -462,7 +462,7 @@ fn test_validator_join() { #[test] fn test_inflation() { heavy_test(|| { - run_actix_until_stop(async move { + run_actix(async move { let num_nodes = 1; let dirs = (0..num_nodes) .map(|i| { diff --git a/nearcore/tests/sync_nodes.rs b/nearcore/tests/sync_nodes.rs index 3a9ff86cef2..9ba2a3ffa6e 100644 --- a/nearcore/tests/sync_nodes.rs +++ b/nearcore/tests/sync_nodes.rs @@ -6,7 +6,7 @@ use actix::{Actor, Addr, System}; use futures::{future, FutureExt}; use num_rational::Rational; -use near_actix_test_utils::run_actix_until_stop; +use near_actix_test_utils::run_actix; use near_chain::{Block, Chain}; use near_chain_configs::Genesis; use near_client::{ClientActor, GetBlock}; @@ -120,7 +120,7 @@ fn sync_nodes() { let (genesis, genesis_block, near1, near2) = setup_configs(); - run_actix_until_stop(async move { + run_actix(async move { let dir1 = tempfile::Builder::new().prefix("sync_nodes_1").tempdir().unwrap(); let (client1, _, _) = start_with_config(dir1.path(), near1); @@ -158,7 +158,7 @@ fn sync_after_sync_nodes() { let (genesis, genesis_block, near1, near2) = setup_configs(); - run_actix_until_stop(async move { + run_actix(async move { let dir1 = tempfile::Builder::new().prefix("sync_nodes_1").tempdir().unwrap(); let (client1, _, _) = start_with_config(dir1.path(), near1); @@ -230,7 +230,7 @@ fn sync_state_stake_change() { near2.client_config.skip_sync_wait = false; near2.client_config.epoch_sync_enabled = false; - run_actix_until_stop(async move { + run_actix(async move { let dir1 = tempfile::Builder::new().prefix("sync_state_stake_change_1").tempdir().unwrap(); let dir2 = diff --git a/nearcore/tests/sync_state_nodes.rs b/nearcore/tests/sync_state_nodes.rs index 6749ef369da..b20eefd6c13 100644 --- a/nearcore/tests/sync_state_nodes.rs +++ b/nearcore/tests/sync_state_nodes.rs @@ -4,7 +4,7 @@ use std::time::Duration; use actix::{Actor, System}; use futures::{future, FutureExt}; -use near_actix_test_utils::run_actix_until_stop; +use near_actix_test_utils::run_actix; use near_chain_configs::Genesis; use near_client::GetBlock; use near_logger_utils::init_integration_logger; @@ -25,7 +25,7 @@ fn sync_state_nodes() { near1.network_config.boot_nodes = convert_boot_nodes(vec![]); near1.client_config.min_num_peers = 0; near1.client_config.epoch_sync_enabled = false; - run_actix_until_stop(async move { + run_actix(async move { let dir1 = tempfile::Builder::new().prefix("sync_nodes_1").tempdir().unwrap(); let (_, view_client1, _) = start_with_config(dir1.path(), near1); @@ -112,7 +112,7 @@ fn sync_state_nodes_multishard() { Genesis::test_sharded(vec!["test1", "test2", "test3", "test4"], 4, vec![2, 2]); genesis.config.epoch_length = 150; // so that by the time test2 joins it is not kicked out yet - run_actix_until_stop(async move { + run_actix(async move { let (port1, port2, port3, port4) = (open_port(), open_port(), open_port(), open_port()); let mut near1 = load_test_config("test1", port1, genesis.clone()); @@ -246,7 +246,7 @@ fn sync_empty_state() { let mut genesis = Genesis::test_sharded(vec!["test1", "test2"], 1, vec![1, 1, 1, 1]); genesis.config.epoch_length = 20; - run_actix_until_stop(async move { + run_actix(async move { let (port1, port2) = (open_port(), open_port()); let state_sync_horizon = 10; let block_header_fetch_horizon = 1; diff --git a/test-utils/actix-test-utils/src/lib.rs b/test-utils/actix-test-utils/src/lib.rs index 4ecdda29f70..ab81155d433 100644 --- a/test-utils/actix-test-utils/src/lib.rs +++ b/test-utils/actix-test-utils/src/lib.rs @@ -14,7 +14,7 @@ impl ShutdownableThread { { let (tx, rx) = std::sync::mpsc::channel(); let join = std::thread::spawn(move || { - run_actix_until_stop(async move { + run_actix(async move { f(); tx.send(actix_rt::System::current()).unwrap(); }); @@ -64,7 +64,7 @@ pub fn spawn_interruptible( actix_rt::spawn(handle_interrupt!(f)) } -fn run_actix_until(f: F, expect_panic: bool) { +pub fn run_actix(f: F) { static SET_PANIC_HOOK: std::sync::Once = std::sync::Once::new(); // This is a workaround to make actix/tokio runtime stop when a task panics. @@ -72,13 +72,11 @@ fn run_actix_until(f: F, expect_panic: bool) { SET_PANIC_HOOK.call_once(|| { let default_hook = std::panic::take_hook(); std::panic::set_hook(Box::new(move |info| { - if !expect_panic { - default_hook(info); - } if actix_rt::System::is_registered() { let exit_code = if CAUGHT_SIGINT.load(Ordering::SeqCst) { 130 } else { 1 }; actix_rt::System::current().stop_with_code(exit_code); } + default_hook(info); })); }); @@ -104,11 +102,3 @@ fn run_actix_until(f: F, expect_panic: bool) { sys.block_on(handle_interrupt!(f)); sys.run().unwrap(); } - -pub fn run_actix_until_stop(f: F) { - run_actix_until(f, false) -} - -pub fn run_actix_until_panic(f: F) { - run_actix_until(f, true) -} diff --git a/test-utils/testlib/src/node/process_node.rs b/test-utils/testlib/src/node/process_node.rs index ea881530cd8..84b69c18c06 100644 --- a/test-utils/testlib/src/node/process_node.rs +++ b/test-utils/testlib/src/node/process_node.rs @@ -53,7 +53,7 @@ impl Node for ProcessNode { self.state = ProcessNodeState::Running(child); let client_addr = format!("http://{}", self.config.rpc_addr().unwrap()); thread::sleep(Duration::from_secs(3)); - near_actix_test_utils::run_actix_until_stop(async move { + near_actix_test_utils::run_actix(async move { WaitOrTimeout::new( Box::new(move |_| { actix::spawn(