diff --git a/nano/core_test/active_transactions.cpp b/nano/core_test/active_transactions.cpp index cb54257cc5..0b381bd64e 100644 --- a/nano/core_test/active_transactions.cpp +++ b/nano/core_test/active_transactions.cpp @@ -51,10 +51,7 @@ TEST (active_transactions, confirm_active) nano::lock_guard guard (node2.rep_crawler.probable_reps_mutex); node2.rep_crawler.probable_reps.emplace (nano::test_genesis_key.pub, nano::genesis_amount, *peers.begin ()); } - while (node2.ledger.cache.cemented_count < 2 || !node2.active.empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node2.ledger.cache.cemented_count == 2 && node2.active.empty ()); // At least one confirmation request ASSERT_GT (election->confirmation_request_count, 0u); // Blocks were cleared (except for not_an_account) @@ -84,11 +81,7 @@ TEST (active_transactions, confirm_frontier) node_flags2.disable_rep_crawler = true; auto & node2 = *system.add_node (node_flags2); ASSERT_EQ (nano::process_result::progress, node2.process (*send).code); - system.deadline_set (5s); - while (node2.active.empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, !node2.active.empty ()); // Save election to check request count afterwards auto election = node2.active.election (send->qualified_root ()); ASSERT_NE (nullptr, election); @@ -101,11 +94,7 @@ TEST (active_transactions, confirm_frontier) nano::lock_guard guard (node2.rep_crawler.probable_reps_mutex); node2.rep_crawler.probable_reps.emplace (nano::test_genesis_key.pub, nano::genesis_amount, *peers.begin ()); } - system.deadline_set (5s); - while (node2.ledger.cache.cemented_count < 2 || !node2.active.empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node2.ledger.cache.cemented_count == 2 && node2.active.empty ()); ASSERT_GT (election->confirmation_request_count, 0u); } } @@ -161,11 +150,7 @@ TEST (active_transactions, adjusted_multiplier_priority) node1.process_active (open1); // key1 node1.process_active (open2); // key2 nano::blocks_confirm (node1, { send1, send2, open1, open2 }); - system.deadline_set (10s); - while (node1.active.size () != 4) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1.active.size () == 4); // Check adjusted difficulty { @@ -187,11 +172,7 @@ TEST (active_transactions, adjusted_multiplier_priority) node1.active.roots.begin ()->election->confirm_once (); } } - system.deadline_set (10s); - while (node1.ledger.cache.cemented_count < 5 || !node1.active.empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1.ledger.cache.cemented_count == 5 && node1.active.empty ()); //genesis and key1,key2 are opened //start chain of 2 on each @@ -258,11 +239,7 @@ TEST (active_transactions, adjusted_multiplier_priority) node1.process_active (send8); // key2 nano::blocks_confirm (node1, { send3, send4, send5, send6, send7, send8 }); - system.deadline_set (10s); - while (node1.active.size () != 6) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1.active.size () == 6); // Check adjusted difficulty nano::lock_guard lock (node1.active.mutex); @@ -302,12 +279,8 @@ TEST (active_transactions, keep_local) auto send4 (wallet.send_action (nano::test_genesis_key.pub, key4.pub, node.config.receive_minimum.number ())); auto send5 (wallet.send_action (nano::test_genesis_key.pub, key5.pub, node.config.receive_minimum.number ())); auto send6 (wallet.send_action (nano::test_genesis_key.pub, key6.pub, node.config.receive_minimum.number ())); - system.deadline_set (5s); // should not drop wallet created transactions - while (node.active.size () != 6) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node.active.size () == 6); ASSERT_EQ (0, node.active.recently_dropped.size ()); while (!node.active.empty ()) { @@ -349,12 +322,8 @@ TEST (active_transactions, keep_local) node.process_active (open2); node.process_active (open3); node.block_processor.flush (); - system.deadline_set (5s); // bound elections, should drop after one loop - while (node.active.size () != node_config.active_elections_size) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node.active.size () == node_config.active_elections_size); ASSERT_EQ (1, node.active.recently_dropped.size ()); ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::election_drop)); } @@ -446,11 +415,7 @@ TEST (active_transactions, prioritize_chains) node1.process_active (open1); node1.process_active (send5); nano::blocks_confirm (node1, { send1, open1, send5 }); - system.deadline_set (10s); - while (node1.active.size () != 3) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1.active.size () == 3); while (!node1.active.empty ()) { nano::lock_guard active_guard (node1.active.mutex); @@ -464,19 +429,10 @@ TEST (active_transactions, prioritize_chains) node1.process_active (send4); node1.process_active (send6); nano::blocks_confirm (node1, { send2, send3, send4, send6 }); - system.deadline_set (10s); - while (node1.active.size () != 4) - { - ASSERT_NO_ERROR (system.poll ()); - } - system.deadline_set (10s); + ASSERT_TIMELY (10s, node1.active.size () == 4); std::this_thread::sleep_for (1s); node1.process_active (open2); - system.deadline_set (10s); - while (node1.active.size () != 4) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1.active.size () == 4); size_t seen (0); { nano::lock_guard active_guard (node1.active.mutex); @@ -510,18 +466,10 @@ TEST (active_transactions, inactive_votes_cache) .build_shared (); auto vote (std::make_shared (nano::test_genesis_key.pub, nano::test_genesis_key.prv, 0, std::vector (1, send->hash ()))); node.vote_processor.vote (vote, std::make_shared (node.network.udp_channels, node.network.endpoint (), node.network_params.protocol.protocol_version)); - system.deadline_set (5s); - while (node.active.inactive_votes_cache_size () != 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node.active.inactive_votes_cache_size () == 1); node.process_active (send); node.block_processor.flush (); - system.deadline_set (5s); - while (!node.ledger.block_confirmed (node.store.tx_begin_read (), send->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node.ledger.block_confirmed (node.store.tx_begin_read (), send->hash ())); ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::vote_cached)); } @@ -549,11 +497,7 @@ TEST (active_transactions, inactive_votes_cache_fork) auto vote (std::make_shared (nano::test_genesis_key.pub, nano::test_genesis_key.prv, 0, std::vector (1, send1->hash ()))); node.vote_processor.vote (vote, std::make_shared (node.network.udp_channels, node.network.endpoint (), node.network_params.protocol.protocol_version)); auto channel1 (node.network.udp_channels.create (node.network.endpoint ())); - system.deadline_set (5s); - while (node.active.inactive_votes_cache_size () != 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node.active.inactive_votes_cache_size () == 1); node.network.process_message (nano::publish (send2), channel1); node.block_processor.flush (); ASSERT_NE (nullptr, node.block (send2->hash ())); @@ -598,11 +542,7 @@ TEST (active_transactions, inactive_votes_cache_existing_vote) node.process_active (send); node.block_processor.add (open); node.block_processor.flush (); - system.deadline_set (5s); - while (node.active.size () != 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node.active.size () == 1); std::shared_ptr election; { nano::lock_guard active_guard (node.active.mutex); @@ -903,11 +843,7 @@ TEST (active_transactions, activate_dependencies) // Establish a representative node2->process_active (block0); node2->block_processor.flush (); - system.deadline_set (10s); - while (node1->block (block0->hash ()) == nullptr) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->block (block0->hash ())); auto block1 = builder.state () .account (nano::test_genesis_key.pub) .previous (block0->hash ()) @@ -936,17 +872,9 @@ TEST (active_transactions, activate_dependencies) node2->process_active (block2); node2->block_processor.flush (); node2->block_confirm (block2); - system.deadline_set (10s); - while (node1->block (block2->hash ()) == nullptr) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->block (block2->hash ())); ASSERT_NE (nullptr, node1->block (block2->hash ())); - system.deadline_set (10s); - while (!node1->active.empty () || !node2->active.empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->active.empty () && node2->active.empty ()); ASSERT_TRUE (node1->block_confirmed_or_being_confirmed (node1->store.tx_begin_read (), block2->hash ())); ASSERT_TRUE (node2->block_confirmed_or_being_confirmed (node2->store.tx_begin_read (), block2->hash ())); } @@ -1010,11 +938,7 @@ TEST (active_transactions, dropped_cleanup) node.worker.push_task ([&flag]() { flag = true; }); - system.deadline_set (5s); - while (!flag) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, flag); // The filter must have been cleared ASSERT_FALSE (node.network.publish_filter.apply (block_bytes.data (), block_bytes.size ())); @@ -1262,11 +1186,7 @@ TEST (active_transactions, vote_generator_session) generator_session.flush (); }); thread.join (); - system.deadline_set (5s); - while (node->stats.count (nano::stat::type::vote, nano::stat::detail::vote_indeterminate) < (100 / nano::network::confirm_ack_hashes_max)) - { - ASSERT_NO_ERROR (system.poll (5ms)); - } + ASSERT_TIMELY (5s, node->stats.count (nano::stat::type::vote, nano::stat::detail::vote_indeterminate) == (100 / nano::network::confirm_ack_hashes_max)); } } @@ -1457,18 +1377,10 @@ TEST (active_transactions, confirm_new) auto & node2 = *system.add_node (); // Add key to node2 system.wallet (1)->insert_adhoc (nano::test_genesis_key.prv); - system.deadline_set (5s); // Let node2 know about the block - while (node2.block (send->hash ()) == nullptr) - { - ASSERT_NO_ERROR (system.poll ()); - } - system.deadline_set (5s); + ASSERT_TIMELY (5s, node2.block (send->hash ())); // Wait confirmation - while (node1.ledger.cache.cemented_count < 2 || node2.ledger.cache.cemented_count < 2) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node1.ledger.cache.cemented_count == 2 && node2.ledger.cache.cemented_count == 2); } TEST (active_transactions, restart_dropped) diff --git a/nano/core_test/bootstrap.cpp b/nano/core_test/bootstrap.cpp index 30acac54cf..e32b6498a6 100644 --- a/nano/core_test/bootstrap.cpp +++ b/nano/core_test/bootstrap.cpp @@ -205,11 +205,7 @@ TEST (bootstrap_processor, process_one) ASSERT_NE (hash1, hash2); node1->bootstrap_initiator.bootstrap (node0->network.endpoint ()); ASSERT_NE (node1->latest (nano::test_genesis_key.pub), node0->latest (nano::test_genesis_key.pub)); - system.deadline_set (10s); - while (node1->latest (nano::test_genesis_key.pub) != node0->latest (nano::test_genesis_key.pub)) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->latest (nano::test_genesis_key.pub) == node0->latest (nano::test_genesis_key.pub)); ASSERT_EQ (0, node1->active.size ()); node1->stop (); } @@ -235,11 +231,7 @@ TEST (bootstrap_processor, process_two) ASSERT_FALSE (node1->init_error ()); node1->bootstrap_initiator.bootstrap (node0->network.endpoint ()); ASSERT_NE (node1->latest (nano::test_genesis_key.pub), node0->latest (nano::test_genesis_key.pub)); - system.deadline_set (10s); - while (node1->latest (nano::test_genesis_key.pub) != node0->latest (nano::test_genesis_key.pub)) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->latest (nano::test_genesis_key.pub) == node0->latest (nano::test_genesis_key.pub)); node1->stop (); } @@ -265,11 +257,7 @@ TEST (bootstrap_processor, process_state) ASSERT_NE (node1->latest (nano::test_genesis_key.pub), block2->hash ()); node1->bootstrap_initiator.bootstrap (node0->network.endpoint ()); ASSERT_NE (node1->latest (nano::test_genesis_key.pub), node0->latest (nano::test_genesis_key.pub)); - system.deadline_set (10s); - while (node1->latest (nano::test_genesis_key.pub) != node0->latest (nano::test_genesis_key.pub)) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->latest (nano::test_genesis_key.pub) == node0->latest (nano::test_genesis_key.pub)); ASSERT_EQ (0, node1->active.size ()); node1->stop (); } @@ -288,21 +276,13 @@ TEST (bootstrap_processor, process_new) nano::keypair key2; system.wallet (1)->insert_adhoc (key2.prv); ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, node1->config.receive_minimum.number ())); - system.deadline_set (10s); - while (node1->balance (key2.pub).is_zero ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, !node1->balance (key2.pub).is_zero ()); nano::uint128_t balance1 (node1->balance (nano::test_genesis_key.pub)); nano::uint128_t balance2 (node1->balance (key2.pub)); auto node3 (std::make_shared (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.alarm, system.logging, system.work)); ASSERT_FALSE (node3->init_error ()); node3->bootstrap_initiator.bootstrap (node1->network.endpoint ()); - system.deadline_set (10s); - while (node3->balance (key2.pub) != balance2) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node3->balance (key2.pub) == balance2); ASSERT_EQ (balance1, node3->balance (nano::test_genesis_key.pub)); node3->stop (); } @@ -327,11 +307,7 @@ TEST (bootstrap_processor, pull_diamond) auto node1 (std::make_shared (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.alarm, system.logging, system.work)); ASSERT_FALSE (node1->init_error ()); node1->bootstrap_initiator.bootstrap (node0->network.endpoint ()); - system.deadline_set (10s); - while (node1->balance (nano::test_genesis_key.pub) != 100) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->balance (nano::test_genesis_key.pub) == 100); ASSERT_EQ (100, node1->balance (nano::test_genesis_key.pub)); node1->stop (); } @@ -354,11 +330,7 @@ TEST (bootstrap_processor, DISABLED_pull_requeue_network_error) node1->bootstrap_initiator.bootstrap (node2->network.endpoint ()); auto attempt (node1->bootstrap_initiator.current_attempt ()); ASSERT_NE (nullptr, attempt); - system.deadline_set (2s); - while (!attempt->frontiers_received) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (2s, attempt->frontiers_received); // Add non-existing pull & stop remote peer { nano::unique_lock lock (node1->bootstrap_initiator.connections->mutex); @@ -368,11 +340,7 @@ TEST (bootstrap_processor, DISABLED_pull_requeue_network_error) node1->bootstrap_initiator.connections->request_pull (lock); node2->stop (); } - system.deadline_set (5s); - while (attempt != nullptr && attempt->requeued_pulls < 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, attempt == nullptr || attempt->requeued_pulls == 1); ASSERT_EQ (0, node1->stats.count (nano::stat::type::bootstrap, nano::stat::detail::bulk_pull_failed_account, nano::stat::dir::in)); // Requeue is not increasing failed attempts } @@ -421,20 +389,12 @@ TEST (bootstrap_processor, frontiers_unconfirmed) node_config.peering_port = nano::get_available_port (); node_flags.disable_legacy_bootstrap = false; auto node3 = system.add_node (node_config, node_flags); - system.deadline_set (5s); - while (node3->rep_crawler.representative_count () == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node3->rep_crawler.representative_count () != 0); //Add single excluded peers record (2 records are required to drop peer) node3->network.excluded_peers.add (nano::transport::map_endpoint_to_tcp (node1->network.endpoint ()), 0); ASSERT_FALSE (node3->network.excluded_peers.check (nano::transport::map_endpoint_to_tcp (node1->network.endpoint ()))); node3->bootstrap_initiator.bootstrap (node1->network.endpoint ()); - system.deadline_set (15s); - while (node3->bootstrap_initiator.in_progress ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (15s, !node3->bootstrap_initiator.in_progress ()); ASSERT_FALSE (node3->ledger.block_exists (send1->hash ())); ASSERT_FALSE (node3->ledger.block_exists (open1->hash ())); ASSERT_EQ (1, node3->stats.count (nano::stat::type::bootstrap, nano::stat::detail::frontier_confirmation_failed, nano::stat::dir::in)); // failed request from node1 @@ -477,17 +437,9 @@ TEST (bootstrap_processor, frontiers_confirmed) node_flags.disable_legacy_bootstrap = false; node_flags.disable_rep_crawler = false; auto node2 = system.add_node (node_config, node_flags); - system.deadline_set (5s); - while (node2->rep_crawler.representative_count () == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node2->rep_crawler.representative_count () != 0); node2->bootstrap_initiator.bootstrap (node1->network.endpoint ()); - system.deadline_set (10s); - while (node2->bootstrap_initiator.current_attempt () != nullptr && !node2->bootstrap_initiator.current_attempt ()->frontiers_confirmed) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node2->bootstrap_initiator.current_attempt () == nullptr || node2->bootstrap_initiator.current_attempt ()->frontiers_confirmed); ASSERT_EQ (1, node2->stats.count (nano::stat::type::bootstrap, nano::stat::detail::frontier_confirmation_successful, nano::stat::dir::in)); // Successful request from node1 ASSERT_EQ (0, node2->stats.count (nano::stat::type::bootstrap, nano::stat::detail::frontier_confirmation_failed, nano::stat::dir::in)); } @@ -534,17 +486,9 @@ TEST (bootstrap_processor, frontiers_unconfirmed_threshold) auto node3 = system.add_node (node_config, node_flags); ASSERT_EQ (nano::process_result::progress, node3->process (*send1).code); ASSERT_EQ (nano::process_result::progress, node3->process (*open1).code); // Change known representative weight - system.deadline_set (5s); - while (node3->rep_crawler.representative_count () < 2) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node3->rep_crawler.representative_count () == 2); node3->bootstrap_initiator.bootstrap (node1->network.endpoint ()); - system.deadline_set (15s); - while (node3->stats.count (nano::stat::type::bootstrap, nano::stat::detail::frontier_confirmation_failed, nano::stat::dir::in) < 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (15s, node3->stats.count (nano::stat::type::bootstrap, nano::stat::detail::frontier_confirmation_failed, nano::stat::dir::in) == 1); ASSERT_FALSE (node3->ledger.block_exists (send2->hash ())); ASSERT_FALSE (node3->ledger.block_exists (open2->hash ())); ASSERT_EQ (1, node3->stats.count (nano::stat::type::bootstrap, nano::stat::detail::frontier_confirmation_failed, nano::stat::dir::in)); // failed confirmation @@ -572,11 +516,7 @@ TEST (bootstrap_processor, push_diamond) auto receive (std::make_shared (send1->hash (), send2->hash (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (send1->hash ()))); ASSERT_EQ (nano::process_result::progress, node1->process (*receive).code); node1->bootstrap_initiator.bootstrap (node0->network.endpoint ()); - system.deadline_set (10s); - while (node0->balance (nano::test_genesis_key.pub) != 100) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node0->balance (nano::test_genesis_key.pub) == 100); ASSERT_EQ (100, node0->balance (nano::test_genesis_key.pub)); node1->stop (); } @@ -596,11 +536,7 @@ TEST (bootstrap_processor, push_one) ASSERT_NE (nullptr, wallet->send_action (nano::test_genesis_key.pub, key1.pub, 100)); ASSERT_NE (balance1, node1->balance (nano::test_genesis_key.pub)); node1->bootstrap_initiator.bootstrap (node0->network.endpoint ()); - system.deadline_set (10s); - while (node0->balance (nano::test_genesis_key.pub) == balance1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node0->balance (nano::test_genesis_key.pub) != balance1); node1->stop (); } @@ -636,11 +572,7 @@ TEST (bootstrap_processor, lazy_hash) ASSERT_EQ (receive2->hash ().to_string (), lazy_attempt->id); } // Check processed blocks - system.deadline_set (10s); - while (node1->balance (key2.pub) == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->balance (key2.pub) != 0); node1->stop (); } @@ -676,11 +608,7 @@ TEST (bootstrap_processor, lazy_hash_bootstrap_id) ASSERT_EQ ("123456", lazy_attempt->id); } // Check processed blocks - system.deadline_set (10s); - while (node1->balance (key2.pub) == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->balance (key2.pub) != 0); node1->stop (); } @@ -717,11 +645,7 @@ TEST (bootstrap_processor, lazy_max_pull_count) node1->network.udp_channels.insert (node0->network.endpoint (), node1->network_params.protocol.protocol_version); node1->bootstrap_initiator.bootstrap_lazy (change3->hash ()); // Check processed blocks - system.deadline_set (10s); - while (node1->block (change3->hash ()) == nullptr) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->block (change3->hash ())); auto transaction = node1->store.tx_begin_read (); ASSERT_EQ (node1->ledger.cache.unchecked_count, node1->store.unchecked_count (transaction)); @@ -753,11 +677,7 @@ TEST (bootstrap_processor, lazy_unclear_state_link) node2->network.udp_channels.insert (node1->network.endpoint (), node1->network_params.protocol.protocol_version); node2->bootstrap_initiator.bootstrap_lazy (receive->hash ()); // Check processed blocks - system.deadline_set (10s); - while (node2->bootstrap_initiator.in_progress ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, !node2->bootstrap_initiator.in_progress ()); node2->block_processor.flush (); ASSERT_TRUE (node2->ledger.block_exists (send1->hash ())); ASSERT_TRUE (node2->ledger.block_exists (send2->hash ())); @@ -789,11 +709,7 @@ TEST (bootstrap_processor, lazy_unclear_state_link_not_existing) node2->network.udp_channels.insert (node1->network.endpoint (), node1->network_params.protocol.protocol_version); node2->bootstrap_initiator.bootstrap_lazy (send2->hash ()); // Check processed blocks - system.deadline_set (15s); - while (node2->bootstrap_initiator.in_progress ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (15s, !node2->bootstrap_initiator.in_progress ()); node2->block_processor.flush (); ASSERT_TRUE (node2->ledger.block_exists (send1->hash ())); ASSERT_TRUE (node2->ledger.block_exists (open->hash ())); @@ -826,11 +742,7 @@ TEST (bootstrap_processor, lazy_destinations) node2->network.udp_channels.insert (node1->network.endpoint (), node1->network_params.protocol.protocol_version); node2->bootstrap_initiator.bootstrap_lazy (send2->hash ()); // Check processed blocks - system.deadline_set (10s); - while (node2->bootstrap_initiator.in_progress ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, !node2->bootstrap_initiator.in_progress ()); node2->block_processor.flush (); ASSERT_TRUE (node2->ledger.block_exists (send1->hash ())); ASSERT_TRUE (node2->ledger.block_exists (send2->hash ())); @@ -874,11 +786,7 @@ TEST (bootstrap_processor, wallet_lazy_frontier) ASSERT_EQ (key2.pub.to_account (), wallet_attempt->id); } // Check processed blocks - system.deadline_set (10s); - while (!node1->ledger.block_exists (receive2->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->ledger.block_exists (receive2->hash ())); node1->stop (); } @@ -911,11 +819,7 @@ TEST (bootstrap_processor, wallet_lazy_pending) wallet->insert_adhoc (key2.prv); node1->bootstrap_wallet (); // Check processed blocks - system.deadline_set (10s); - while (!node1->ledger.block_exists (send2->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->ledger.block_exists (send2->hash ())); node1->stop (); } @@ -950,27 +854,15 @@ TEST (bootstrap_processor, multiple_attempts) node2->bootstrap_initiator.bootstrap (); auto lazy_attempt (node2->bootstrap_initiator.current_lazy_attempt ()); auto legacy_attempt (node2->bootstrap_initiator.current_attempt ()); - system.deadline_set (5s); - while (!lazy_attempt->started || !legacy_attempt->started) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, lazy_attempt->started && legacy_attempt->started); // Check that both bootstrap attempts are running & not finished ASSERT_FALSE (lazy_attempt->stopped); ASSERT_FALSE (legacy_attempt->stopped); ASSERT_GE (node2->bootstrap_initiator.attempts.size (), 2); // Check processed blocks - system.deadline_set (10s); - while (node2->balance (key2.pub) == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node2->balance (key2.pub) != 0); // Check attempts finish - system.deadline_set (5s); - while (node2->bootstrap_initiator.attempts.size () != 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node2->bootstrap_initiator.attempts.size () == 0); node2->stop (); } @@ -1112,11 +1004,7 @@ TEST (bulk, genesis) nano::block_hash latest3 (node1->latest (nano::test_genesis_key.pub)); ASSERT_NE (latest1, latest3); node2->bootstrap_initiator.bootstrap (node1->network.endpoint ()); - system.deadline_set (10s); - while (node2->latest (nano::test_genesis_key.pub) != node1->latest (nano::test_genesis_key.pub)) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node2->latest (nano::test_genesis_key.pub) == node1->latest (nano::test_genesis_key.pub)); ASSERT_EQ (node2->latest (nano::test_genesis_key.pub), node1->latest (nano::test_genesis_key.pub)); node2->stop (); } @@ -1141,29 +1029,19 @@ TEST (bulk, offline_send) ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, node1->config.receive_minimum.number ())); ASSERT_NE (std::numeric_limits::max (), node1->balance (nano::test_genesis_key.pub)); // Wait to finish election background tasks - system.deadline_set (10s); - while (!node1->active.empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->active.empty ()); // Initiate bootstrap node2->bootstrap_initiator.bootstrap (node1->network.endpoint ()); // Nodes should find each other + system.deadline_set (10s); do { ASSERT_NO_ERROR (system.poll ()); } while (node1->network.empty () || node2->network.empty ()); // Send block arrival via bootstrap - while (node2->balance (nano::test_genesis_key.pub) == std::numeric_limits::max ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node2->balance (nano::test_genesis_key.pub) != std::numeric_limits::max ()); // Receiving send block - system.deadline_set (20s); - while (node2->balance (key2.pub) != node1->config.receive_minimum.number ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (20s, node2->balance (key2.pub) == node1->config.receive_minimum.number ()); node2->stop (); } @@ -1177,11 +1055,7 @@ TEST (bulk_pull_account, basics) auto send1 (system.wallet (0)->send_action (nano::genesis_account, key1.pub, 25)); auto send2 (system.wallet (0)->send_action (nano::genesis_account, key1.pub, 10)); auto send3 (system.wallet (0)->send_action (nano::genesis_account, key1.pub, 2)); - system.deadline_set (5s); - while (system.nodes[0]->balance (key1.pub) != 25) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, system.nodes[0]->balance (key1.pub) == 25); auto connection (std::make_shared (nullptr, system.nodes[0])); { diff --git a/nano/core_test/confirmation_height.cpp b/nano/core_test/confirmation_height.cpp index f42996393d..67757730b0 100644 --- a/nano/core_test/confirmation_height.cpp +++ b/nano/core_test/confirmation_height.cpp @@ -53,11 +53,7 @@ TEST (confirmation_height, single) node->process_active (send1); node->block_processor.flush (); - system.deadline_set (10s); - while (node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) != 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 1); { auto transaction = node->store.tx_begin_write (); @@ -162,11 +158,7 @@ TEST (confirmation_height, multiple_accounts) election->confirm_once (); } - system.deadline_set (10s); - while (node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) != 10) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 10); nano::account_info account_info; nano::confirmation_height_info confirmation_height_info; @@ -367,11 +359,7 @@ TEST (confirmation_height, gap_live) election->confirm_once (); } - system.deadline_set (10s); - while (node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) != 6) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 6); // This should confirm the open block and the source of the receive blocks auto transaction (node->store.tx_begin_read ()); @@ -457,11 +445,7 @@ TEST (confirmation_height, send_receive_between_2_accounts) election->confirm_once (); } - system.deadline_set (10s); - while (node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) != 10) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 10); auto transaction (node->store.tx_begin_read ()); ASSERT_TRUE (node->ledger.block_confirmed (transaction, receive4->hash ())); @@ -535,11 +519,7 @@ TEST (confirmation_height, send_receive_self) election->confirm_once (); } - system.deadline_set (10s); - while (node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) != 6) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 6); auto transaction (node->store.tx_begin_read ()); ASSERT_TRUE (node->ledger.block_confirmed (transaction, receive3->hash ())); @@ -639,11 +619,7 @@ TEST (confirmation_height, all_block_types) election->confirm_once (); } - system.deadline_set (10s); - while (node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) != 15) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 15); auto transaction (node->store.tx_begin_read ()); ASSERT_TRUE (node->ledger.block_confirmed (transaction, state_send2->hash ())); @@ -811,11 +787,7 @@ TEST (confirmation_height, observers) node1->process_active (send1); node1->block_processor.flush (); - system.deadline_set (10s); - while (node1->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) != 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 1); auto transaction = node1->store.tx_begin_read (); ASSERT_TRUE (node1->ledger.block_confirmed (transaction, send1->hash ())); ASSERT_EQ (1, node1->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in)); @@ -991,12 +963,8 @@ TEST (confirmation_height, pending_observer_callbacks) node->confirmation_height_processor.add (send1->hash ()); - system.deadline_set (10s); // Confirm the callback is not called under this circumstance because there is no election information - while (node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) != 1 || node->ledger.stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::all, nano::stat::dir::out) != 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 1 && node->ledger.stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::all, nano::stat::dir::out) == 1); ASSERT_EQ (2, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in)); ASSERT_EQ (2, node->stats.count (nano::stat::type::confirmation_height, get_stats_detail (mode_a), nano::stat::dir::in)); @@ -1133,11 +1101,7 @@ TEST (confirmation_height, prioritize_frontiers) node->active.confirm_prioritized_frontiers (transaction); // Check that the active transactions roots contains the frontiers - system.deadline_set (std::chrono::seconds (10)); - while (node->active.size () != num_accounts) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->active.size () == num_accounts); std::array frontiers{ send17.qualified_root (), send6.qualified_root (), send7.qualified_root (), open2.qualified_root (), send11.qualified_root () }; for (auto & frontier : frontiers) @@ -1170,11 +1134,7 @@ TEST (confirmation_height, frontiers_confirmation_mode) auto transaction = node->store.tx_begin_write (); ASSERT_EQ (nano::process_result::progress, node->ledger.process (transaction, send).code); } - system.deadline_set (5s); - while (node->active.size () != 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node->active.size () == 1); } // Auto mode { @@ -1187,11 +1147,7 @@ TEST (confirmation_height, frontiers_confirmation_mode) auto transaction = node->store.tx_begin_write (); ASSERT_EQ (nano::process_result::progress, node->ledger.process (transaction, send).code); } - system.deadline_set (5s); - while (node->active.size () != 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node->active.size () == 1); } // Disabled mode { @@ -1255,12 +1211,7 @@ TEST (confirmation_height, callback_confirmed_history) nano::lock_guard guard (node->active.mutex); election->confirm_once (); } - system.deadline_set (10s); - while (node->active.size () > 0) - { - ASSERT_NO_ERROR (system.poll ()); - } - + ASSERT_TIMELY (10s, node->active.size () == 0); ASSERT_EQ (0, node->active.list_recently_cemented ().size ()); { nano::lock_guard guard (node->active.mutex); @@ -1270,36 +1221,19 @@ TEST (confirmation_height, callback_confirmed_history) auto transaction = node->store.tx_begin_read (); ASSERT_FALSE (node->ledger.block_confirmed (transaction, send->hash ())); - system.deadline_set (10s); - while (!node->write_database_queue.contains (nano::writer::confirmation_height)) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->write_database_queue.contains (nano::writer::confirmation_height)); // Confirm that no inactive callbacks have been called when the confirmation height processor has already iterated over it, waiting to write ASSERT_EQ (0, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::inactive_conf_height, nano::stat::dir::out)); } - system.deadline_set (10s); - while (node->write_database_queue.contains (nano::writer::confirmation_height)) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, !node->write_database_queue.contains (nano::writer::confirmation_height)); auto transaction = node->store.tx_begin_read (); ASSERT_TRUE (node->ledger.block_confirmed (transaction, send->hash ())); - system.deadline_set (10s); - while (node->active.size () > 0) - { - ASSERT_NO_ERROR (system.poll ()); - } - - system.deadline_set (10s); - while (node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_quorum, nano::stat::dir::out) != 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->active.size () == 0); + ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_quorum, nano::stat::dir::out) == 1); ASSERT_EQ (1, node->active.list_recently_cemented ().size ()); ASSERT_EQ (0, node->active.blocks.size ()); @@ -1356,11 +1290,7 @@ TEST (confirmation_height, dependent_election) election->confirm_once (); } - system.deadline_set (10s); - while (node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) != 3) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 3); ASSERT_EQ (1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_quorum, nano::stat::dir::out)); ASSERT_EQ (1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_conf_height, nano::stat::dir::out)); @@ -1441,11 +1371,7 @@ TEST (confirmation_height, cemented_gap_below_receive) nano::lock_guard guard (node->active.mutex); election->confirm_once (); } - system.deadline_set (10s); - while (node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) != 10) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 10); auto transaction = node->store.tx_begin_read (); ASSERT_TRUE (node->ledger.block_confirmed (transaction, open1->hash ())); @@ -1538,11 +1464,7 @@ TEST (confirmation_height, cemented_gap_below_no_cache) nano::lock_guard guard (node->active.mutex); election->confirm_once (); } - system.deadline_set (10s); - while (node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) != 6) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 6); auto transaction = node->store.tx_begin_read (); ASSERT_TRUE (node->ledger.block_confirmed (transaction, open1->hash ())); @@ -1593,11 +1515,7 @@ TEST (confirmation_height, election_winner_details_clearing) election->confirm_once (); } - system.deadline_set (10s); - while (node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) != 2) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 2); ASSERT_EQ (0, node->active.election_winner_details_size ()); node->block_confirm (send); @@ -1609,11 +1527,7 @@ TEST (confirmation_height, election_winner_details_clearing) } // Wait until this block is confirmed - system.deadline_set (10s); - while (node->active.election_winner_details_size () != 1 && !node->confirmation_height_processor.current ().is_zero ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->active.election_winner_details_size () == 1 || node->confirmation_height_processor.current ().is_zero ()); ASSERT_EQ (1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::inactive_conf_height, nano::stat::dir::out)); @@ -1625,21 +1539,13 @@ TEST (confirmation_height, election_winner_details_clearing) election->confirm_once (); } - system.deadline_set (10s); - while (node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) != 3) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 3); // Add an already cemented block with fake election details. It should get removed node->active.add_election_winner_details (send2->hash (), nullptr); node->confirmation_height_processor.add (send2->hash ()); - system.deadline_set (10s); - while (node->active.election_winner_details_size () > 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->active.election_winner_details_size () == 0); ASSERT_EQ (1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::inactive_conf_height, nano::stat::dir::out)); ASSERT_EQ (3, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out)); diff --git a/nano/core_test/conflicts.cpp b/nano/core_test/conflicts.cpp index 522e5df765..8c84bad543 100644 --- a/nano/core_test/conflicts.cpp +++ b/nano/core_test/conflicts.cpp @@ -253,11 +253,7 @@ TEST (conflicts, adjusted_multiplier) auto send5 (std::make_shared (key3.pub, change1->hash (), nano::test_genesis_key.pub, 0, key4.pub, key3.prv, key3.pub, *system.work.generate (change1->hash ()))); // Pending for open epoch block node1.process_active (send5); nano::blocks_confirm (node1, { send1, send2, receive1, open1, send3, send4, open_epoch1, receive2, open2, change1, send5 }); - system.deadline_set (3s); - while (node1.active.size () != 11) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (3s, node1.active.size () == 11); std::unordered_map adjusted_multipliers; { nano::lock_guard guard (node1.active.mutex); @@ -288,11 +284,7 @@ TEST (conflicts, adjusted_multiplier) node1.process_active (open_epoch2); node1.block_processor.flush (); node1.block_confirm (open_epoch2); - system.deadline_set (3s); - while (node1.active.size () != 12) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (3s, node1.active.size () == 12); { nano::lock_guard guard (node1.active.mutex); node1.active.update_adjusted_multiplier (); diff --git a/nano/core_test/distributed_work.cpp b/nano/core_test/distributed_work.cpp index acd14bcdf5..c5ecfb8738 100644 --- a/nano/core_test/distributed_work.cpp +++ b/nano/core_test/distributed_work.cpp @@ -26,11 +26,7 @@ TEST (distributed_work, no_peers) done = true; }; ASSERT_FALSE (node->distributed_work.make (nano::work_version::work_1, hash, node->config.work_peers, node->network_params.network.publish_thresholds.base, callback, nano::account ())); - system.deadline_set (5s); - while (!done) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, done); ASSERT_GE (nano::work_difficulty (nano::work_version::work_1, hash, *work), node->network_params.network.publish_thresholds.base); // should only be removed after cleanup ASSERT_EQ (1, node->distributed_work.items.size ()); @@ -70,22 +66,14 @@ TEST (distributed_work, no_peers_cancel) // manually cancel node.distributed_work.cancel (hash, true); // forces local stop - system.deadline_set (20s); - while (!done || !node.distributed_work.items.empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (20s, done && node.distributed_work.items.empty ()); // now using observer done = false; ASSERT_FALSE (node.distributed_work.make (nano::work_version::work_1, hash, node.config.work_peers, nano::difficulty::from_multiplier (1e6, node.network_params.network.publish_thresholds.base), callback_to_cancel)); ASSERT_EQ (1, node.distributed_work.items.size ()); node.observers.work_cancel.notify (hash); - system.deadline_set (20s); - while (!done || !node.distributed_work.items.empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (20s, done && node.distributed_work.items.empty ()); } TEST (distributed_work, no_peers_multi) @@ -111,11 +99,7 @@ TEST (distributed_work, no_peers_multi) ASSERT_EQ (hash, requests->first); ASSERT_GE (requests->second.size (), total - 4); } - system.deadline_set (5s); - while (count < total) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, count == total); system.deadline_set (5s); while (!node->distributed_work.items.empty ()) { @@ -135,11 +119,7 @@ TEST (distributed_work, no_peers_multi) { ASSERT_EQ (1, requests.second.size ()); } - system.deadline_set (5s); - while (count < total) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, count == total); system.deadline_set (5s); while (!node->distributed_work.items.empty ()) { @@ -171,11 +151,7 @@ TEST (distributed_work, peer) decltype (node->config.work_peers) peers; peers.emplace_back ("::ffff:127.0.0.1", work_peer->port ()); ASSERT_FALSE (node->distributed_work.make (nano::work_version::work_1, hash, peers, node->network_params.network.publish_thresholds.base, callback, nano::account ())); - system.deadline_set (5s); - while (!done) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, done); ASSERT_GE (nano::work_difficulty (nano::work_version::work_1, hash, *work), node->network_params.network.publish_thresholds.base); ASSERT_EQ (1, work_peer->generations_good); ASSERT_EQ (0, work_peer->generations_bad); @@ -201,17 +177,9 @@ TEST (distributed_work, peer_malicious) decltype (node->config.work_peers) peers; peers.emplace_back ("::ffff:127.0.0.1", malicious_peer->port ()); ASSERT_FALSE (node->distributed_work.make (nano::work_version::work_1, hash, peers, node->network_params.network.publish_thresholds.base, callback, nano::account ())); - system.deadline_set (5s); - while (!done) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, done); ASSERT_GE (nano::work_difficulty (nano::work_version::work_1, hash, *work), node->network_params.network.publish_thresholds.base); - system.deadline_set (5s); - while (malicious_peer->generations_bad < 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, malicious_peer->generations_bad >= 1); // make sure it was *not* the malicious peer that replied ASSERT_EQ (0, malicious_peer->generations_good); // initial generation + the second time when it also starts doing local generation @@ -226,11 +194,7 @@ TEST (distributed_work, peer_malicious) malicious_peer2->start (); peers[0].second = malicious_peer2->port (); ASSERT_FALSE (node->distributed_work.make (nano::work_version::work_1, hash, peers, node->network_params.network.publish_thresholds.base, {}, nano::account ())); - system.deadline_set (5s); - while (malicious_peer2->generations_bad < 2) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, malicious_peer2->generations_bad >= 2); node->distributed_work.cancel (hash); ASSERT_EQ (0, malicious_peer2->cancels); } @@ -259,17 +223,9 @@ TEST (distributed_work, peer_multi) peers.emplace_back ("localhost", slow_peer->port ()); peers.emplace_back ("localhost", good_peer->port ()); ASSERT_FALSE (node->distributed_work.make (nano::work_version::work_1, hash, peers, node->network_params.network.publish_thresholds.base, callback, nano::account ())); - system.deadline_set (5s); - while (!done) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, done); ASSERT_GE (nano::work_difficulty (nano::work_version::work_1, hash, *work), node->network_params.network.publish_thresholds.base); - system.deadline_set (5s); - while (slow_peer->cancels < 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, slow_peer->cancels == 1); ASSERT_EQ (0, malicious_peer->generations_good); ASSERT_EQ (1, malicious_peer->generations_bad); ASSERT_EQ (0, malicious_peer->cancels); @@ -298,10 +254,6 @@ TEST (distributed_work, fail_resolve) decltype (node->config.work_peers) peers; peers.emplace_back ("beeb.boop.123z", 0); ASSERT_FALSE (node->distributed_work.make (nano::work_version::work_1, hash, peers, node->network_params.network.publish_thresholds.base, callback, nano::account ())); - system.deadline_set (5s); - while (!done) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, done); ASSERT_GE (nano::work_difficulty (nano::work_version::work_1, hash, *work), node->network_params.network.publish_thresholds.base); } diff --git a/nano/core_test/gap_cache.cpp b/nano/core_test/gap_cache.cpp index 766c993d25..2e5cf321c3 100644 --- a/nano/core_test/gap_cache.cpp +++ b/nano/core_test/gap_cache.cpp @@ -24,11 +24,7 @@ TEST (gap_cache, add_existing) ASSERT_NE (cache.blocks.get<1> ().end (), existing1); auto arrival (existing1->arrival); lock.unlock (); - system.deadline_set (20s); - while (arrival == std::chrono::steady_clock::now ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (20s, arrival != std::chrono::steady_clock::now ()); cache.add (block1->hash ()); ASSERT_EQ (1, cache.size ()); lock.lock (); @@ -48,11 +44,7 @@ TEST (gap_cache, comparison) ASSERT_NE (cache.blocks.get<1> ().end (), existing1); auto arrival (existing1->arrival); lock.unlock (); - system.deadline_set (20s); - while (std::chrono::steady_clock::now () == arrival) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (20s, std::chrono::steady_clock::now () != arrival); auto block3 (std::make_shared (0, 42, 1, nano::keypair ().prv, 3, 4)); cache.add (block3->hash ()); ASSERT_EQ (2, cache.size ()); diff --git a/nano/core_test/ipc.cpp b/nano/core_test/ipc.cpp index f789fc9f16..2bea00fa15 100644 --- a/nano/core_test/ipc.cpp +++ b/nano/core_test/ipc.cpp @@ -53,11 +53,7 @@ TEST (ipc, asynchronous) }); }); }); - system.deadline_set (5s); - while (!call_completed) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, call_completed); ipc.stop (); } @@ -86,11 +82,7 @@ TEST (ipc, synchronous) }); client_thread.detach (); - system.deadline_set (5s); - while (!call_completed) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, call_completed); ipc.stop (); } diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 5348f9b3fd..b99f199531 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -618,11 +618,7 @@ TEST (system, generate_send_new) ASSERT_EQ (system.wallet (0)->store.end (), iterator2); ASSERT_FALSE (new_account.is_zero ()); } - system.deadline_set (10s); - while (node1.balance (new_account) == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1.balance (new_account) != 0); system.stop (); runner.join (); } diff --git a/nano/core_test/network.cpp b/nano/core_test/network.cpp index de66157331..5e4ce894a6 100644 --- a/nano/core_test/network.cpp +++ b/nano/core_test/network.cpp @@ -87,26 +87,10 @@ TEST (network, send_node_id_handshake) node0->network.send_keepalive (channel); ASSERT_EQ (0, node0->network.size ()); ASSERT_EQ (0, node1->network.size ()); - system.deadline_set (10s); - while (node1->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in) == initial_node1) - { - ASSERT_NO_ERROR (system.poll ()); - } - system.deadline_set (10s); - while (node0->network.size () != 0 && node1->network.size () != 1) - { - ASSERT_NO_ERROR (system.poll ()); - } - system.deadline_set (10s); - while (node0->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in) < initial + 2) - { - ASSERT_NO_ERROR (system.poll ()); - } - system.deadline_set (10s); - while (node0->network.size () != 1 && node1->network.size () != 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in) != initial_node1); + ASSERT_TIMELY (10s, node0->network.size () == 0 || node1->network.size () == 1); + ASSERT_TIMELY (10s, node0->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in) == initial + 2); + ASSERT_TIMELY (10s, node0->network.size () == 1 || node1->network.size () == 1); auto list1 (node0->network.list (1)); ASSERT_EQ (node1->network.endpoint (), list1[0]->get_endpoint ()); auto list2 (node1->network.list (1)); @@ -134,26 +118,10 @@ TEST (network, send_node_id_handshake_tcp) }); ASSERT_EQ (0, node0->network.size ()); ASSERT_EQ (0, node1->network.size ()); - system.deadline_set (10s); - while (node0->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in) < initial + 2) - { - ASSERT_NO_ERROR (system.poll ()); - } - system.deadline_set (5s); - while (node1->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in) < initial_node1 + 2) - { - ASSERT_NO_ERROR (system.poll ()); - } - system.deadline_set (5s); - while (node0->stats.count (nano::stat::type::message, nano::stat::detail::keepalive, nano::stat::dir::in) < initial_keepalive + 2) - { - ASSERT_NO_ERROR (system.poll ()); - } - system.deadline_set (5s); - while (node1->stats.count (nano::stat::type::message, nano::stat::detail::keepalive, nano::stat::dir::in) < initial_keepalive + 2) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node0->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in) >= initial + 2); + ASSERT_TIMELY (5s, node1->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::in) >= initial_node1 + 2); + ASSERT_TIMELY (5s, node0->stats.count (nano::stat::type::message, nano::stat::detail::keepalive, nano::stat::dir::in) >= initial_keepalive + 2); + ASSERT_TIMELY (5s, node1->stats.count (nano::stat::type::message, nano::stat::detail::keepalive, nano::stat::dir::in) >= initial_keepalive + 2); ASSERT_EQ (1, node0->network.size ()); ASSERT_EQ (1, node1->network.size ()); auto list1 (node0->network.list (1)); @@ -177,13 +145,9 @@ TEST (network, last_contacted) system.nodes.push_back (node1); auto channel1 (std::make_shared (node1->network.udp_channels, nano::endpoint (boost::asio::ip::address_v6::loopback (), system.nodes.front ()->network.endpoint ().port ()), node1->network_params.protocol.protocol_version)); node1->network.send_keepalive (channel1); - system.deadline_set (10s); // Wait until the handshake is complete - while (node0->network.size () < 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node0->network.size () == 1); ASSERT_EQ (node0->network.size (), 1); auto channel2 (node0->network.udp_channels.channel (nano::endpoint (boost::asio::ip::address_v6::loopback (), node1->network.endpoint ().port ()))); @@ -191,10 +155,7 @@ TEST (network, last_contacted) // Make sure last_contact gets updated on receiving a non-handshake message auto timestamp_before_keepalive = channel2->get_last_packet_received (); node1->network.send_keepalive (channel1); - while (node0->stats.count (nano::stat::type::message, nano::stat::detail::keepalive, nano::stat::dir::in) < 2) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node0->stats.count (nano::stat::type::message, nano::stat::detail::keepalive, nano::stat::dir::in) == 2); ASSERT_EQ (node0->network.size (), 1); auto timestamp_after_keepalive = channel2->get_last_packet_received (); ASSERT_GT (timestamp_after_keepalive, timestamp_before_keepalive); @@ -218,20 +179,12 @@ TEST (network, multi_keepalive) node1->network.send_keepalive (channel1); ASSERT_EQ (0, node1->network.size ()); ASSERT_EQ (0, node0->network.size ()); - system.deadline_set (10s); - while (node0->network.size () != 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node0->network.size () == 1); auto node2 = system.add_node (node_flags); ASSERT_FALSE (node2->init_error ()); auto channel2 (std::make_shared (node2->network.udp_channels, node0->network.endpoint (), node2->network_params.protocol.protocol_version)); node2->network.send_keepalive (channel2); - system.deadline_set (10s); - while (node1->network.size () != 2 || node0->network.size () != 2 || node2->network.size () != 2) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->network.size () == 2 && node0->network.size () == 2 && node2->network.size () == 2); node1->stop (); node2->stop (); } @@ -249,11 +202,7 @@ TEST (network, send_discarded_publish) ASSERT_EQ (genesis.hash (), node1.ledger.latest (transaction, nano::test_genesis_key.pub)); ASSERT_EQ (genesis.hash (), node2.latest (nano::test_genesis_key.pub)); } - system.deadline_set (10s); - while (node2.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in) == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node2.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in) != 0); auto transaction (node1.store.tx_begin_read ()); ASSERT_EQ (genesis.hash (), node1.ledger.latest (transaction, nano::test_genesis_key.pub)); ASSERT_EQ (genesis.hash (), node2.latest (nano::test_genesis_key.pub)); @@ -272,11 +221,7 @@ TEST (network, send_invalid_publish) ASSERT_EQ (genesis.hash (), node1.ledger.latest (transaction, nano::test_genesis_key.pub)); ASSERT_EQ (genesis.hash (), node2.latest (nano::test_genesis_key.pub)); } - system.deadline_set (10s); - while (node2.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in) == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node2.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in) != 0); auto transaction (node1.store.tx_begin_read ()); ASSERT_EQ (genesis.hash (), node1.ledger.latest (transaction, nano::test_genesis_key.pub)); ASSERT_EQ (genesis.hash (), node2.latest (nano::test_genesis_key.pub)); @@ -304,12 +249,8 @@ TEST (network, send_valid_confirm_ack) nano::send_block block2 (latest1, key2.pub, 50, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (latest1)); nano::block_hash latest2 (node2.latest (nano::test_genesis_key.pub)); node1.process_active (std::make_shared (block2)); - system.deadline_set (10s); // Keep polling until latest block changes - while (node2.latest (nano::test_genesis_key.pub) == latest2) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node2.latest (nano::test_genesis_key.pub) != latest2); // Make sure the balance has decreased after processing the block. ASSERT_EQ (50, node2.balance (nano::test_genesis_key.pub)); } @@ -340,17 +281,9 @@ TEST (network, send_valid_publish) auto hash2 (block2.hash ()); nano::block_hash latest2 (node2.latest (nano::test_genesis_key.pub)); node2.process_active (std::make_shared (block2)); - system.deadline_set (10s); - while (node1.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in) == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in) != 0); ASSERT_NE (hash2, latest2); - system.deadline_set (10s); - while (node2.latest (nano::test_genesis_key.pub) == latest2) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node2.latest (nano::test_genesis_key.pub) != latest2); ASSERT_EQ (50, node2.balance (nano::test_genesis_key.pub)); } } @@ -367,11 +300,7 @@ TEST (network, send_insufficient_work) nano::transport::channel_udp channel (node1.network.udp_channels, node2.network.endpoint (), node1.network_params.protocol.protocol_version); channel.send (publish, [](boost::system::error_code const & ec, size_t size) {}); ASSERT_EQ (0, node1.stats.count (nano::stat::type::error, nano::stat::detail::insufficient_work)); - system.deadline_set (10s); - while (node2.stats.count (nano::stat::type::error, nano::stat::detail::insufficient_work) == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node2.stats.count (nano::stat::type::error, nano::stat::detail::insufficient_work) != 0); ASSERT_EQ (1, node2.stats.count (nano::stat::type::error, nano::stat::detail::insufficient_work)); } @@ -437,11 +366,7 @@ TEST (receivable_processor, send_with_receive) ASSERT_EQ (0, node1.balance (key2.pub)); ASSERT_EQ (amount - node1.config.receive_minimum.number (), node2.balance (nano::test_genesis_key.pub)); ASSERT_EQ (0, node2.balance (key2.pub)); - system.deadline_set (10s); - while (node1.balance (key2.pub) != node1.config.receive_minimum.number () || node2.balance (key2.pub) != node1.config.receive_minimum.number ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1.balance (key2.pub) == node1.config.receive_minimum.number () && node2.balance (key2.pub) == node1.config.receive_minimum.number ()); ASSERT_EQ (amount - node1.config.receive_minimum.number (), node1.balance (nano::test_genesis_key.pub)); ASSERT_EQ (node1.config.receive_minimum.number (), node1.balance (key2.pub)); ASSERT_EQ (amount - node1.config.receive_minimum.number (), node2.balance (nano::test_genesis_key.pub)); @@ -460,11 +385,7 @@ TEST (network, receive_weight_change) system.wallet (1)->store.representative_set (transaction, key2.pub); } ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); - system.deadline_set (10s); - while (std::any_of (system.nodes.begin (), system.nodes.end (), [&](std::shared_ptr const & node_a) { return node_a->weight (key2.pub) != system.nodes[0]->config.receive_minimum.number (); })) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, std::all_of (system.nodes.begin (), system.nodes.end (), [&](std::shared_ptr const & node_a) { return node_a->weight (key2.pub) == system.nodes[0]->config.receive_minimum.number (); })); } TEST (parse_endpoint, valid) @@ -594,11 +515,7 @@ TEST (network, endpoint_bad_fd) auto endpoint (system.nodes[0]->network.endpoint ()); ASSERT_TRUE (endpoint.address ().is_loopback ()); // The endpoint is invalidated asynchronously - system.deadline_set (10s); - while (system.nodes[0]->network.endpoint ().port () != 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, system.nodes[0]->network.endpoint ().port () == 0); } TEST (network, reserved_address) @@ -795,11 +712,7 @@ TEST (tcp_listener, tcp_node_id_handshake) }); }); - system.deadline_set (std::chrono::seconds (5)); - while (!write_done) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, write_done); boost::optional> response_zero (std::make_pair (nano::account (0), nano::signature (0))); nano::node_id_handshake node_id_handshake_response (boost::none, response_zero); @@ -810,11 +723,7 @@ TEST (tcp_listener, tcp_node_id_handshake) ASSERT_EQ (output->size (), size_a); done = true; }); - system.deadline_set (std::chrono::seconds (5)); - while (!done) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, done); } TEST (tcp_listener, tcp_listener_timeout_empty) @@ -827,11 +736,7 @@ TEST (tcp_listener, tcp_listener_timeout_empty) ASSERT_FALSE (ec); connected = true; }); - system.deadline_set (std::chrono::seconds (5)); - while (!connected) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, connected); bool disconnected (false); system.deadline_set (std::chrono::seconds (6)); while (!disconnected) @@ -859,11 +764,7 @@ TEST (tcp_listener, tcp_listener_timeout_node_id_handshake) ASSERT_EQ (input.size (), size_a); }); }); - system.deadline_set (std::chrono::seconds (5)); - while (node0->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake) == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node0->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake) != 0); { nano::lock_guard guard (node0->bootstrap.mutex); ASSERT_EQ (node0->bootstrap.connections.size (), 1); @@ -903,16 +804,8 @@ TEST (network, replace_port) ASSERT_EQ (peers_list[0]->get_node_id (), node1->node_id.pub); auto channel (std::make_shared (node0->network.udp_channels, node1->network.endpoint (), node1->network_params.protocol.protocol_version)); node0->network.send_keepalive (channel); - system.deadline_set (5s); - while (!node0->network.udp_channels.channel (node1->network.endpoint ())) - { - ASSERT_NO_ERROR (system.poll ()); - } - system.deadline_set (5s); - while (node0->network.udp_channels.size () > 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node0->network.udp_channels.channel (node1->network.endpoint ())); + ASSERT_TIMELY (5s, node0->network.udp_channels.size () <= 1); ASSERT_EQ (node0->network.udp_channels.size (), 1); auto list1 (node0->network.list (1)); ASSERT_EQ (node1->network.endpoint (), list1[0]->get_endpoint ()); @@ -920,11 +813,7 @@ TEST (network, replace_port) ASSERT_EQ (node0->network.endpoint (), list2[0]->get_endpoint ()); // Remove correct peer (same node ID) node0->network.udp_channels.clean_node_id (nano::endpoint (node1->network.endpoint ().address (), 23000), node1->node_id.pub); - system.deadline_set (5s); - while (node0->network.udp_channels.size () > 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node0->network.udp_channels.size () <= 1); node1->stop (); } @@ -962,21 +851,13 @@ TEST (network, duplicate_detection) ASSERT_EQ (0, node1.stats.count (nano::stat::type::filter, nano::stat::detail::duplicate_publish)); udp_channel->send (publish); udp_channel->send (publish); - system.deadline_set (2s); - while (node1.stats.count (nano::stat::type::filter, nano::stat::detail::duplicate_publish) < 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (2s, node1.stats.count (nano::stat::type::filter, nano::stat::detail::duplicate_publish) == 1); // Publish duplicate detection through TCP auto tcp_channel (node0.network.tcp_channels.find_channel (nano::transport::map_endpoint_to_tcp (node1.network.endpoint ()))); ASSERT_EQ (1, node1.stats.count (nano::stat::type::filter, nano::stat::detail::duplicate_publish)); tcp_channel->send (publish); - system.deadline_set (2s); - while (node1.stats.count (nano::stat::type::filter, nano::stat::detail::duplicate_publish) < 2) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (2s, node1.stats.count (nano::stat::type::filter, nano::stat::detail::duplicate_publish) == 2); } TEST (network, duplicate_revert_publish) diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index 12ba58594a..6688743208 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -118,11 +118,7 @@ TEST (node, send_self) system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key2.prv); ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); - system.deadline_set (10s); - while (system.nodes[0]->balance (key2.pub).is_zero ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, !system.nodes[0]->balance (key2.pub).is_zero ()); ASSERT_EQ (std::numeric_limits::max () - system.nodes[0]->config.receive_minimum.number (), system.nodes[0]->balance (nano::test_genesis_key.pub)); } @@ -135,11 +131,7 @@ TEST (node, send_single) ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); ASSERT_EQ (std::numeric_limits::max () - system.nodes[0]->config.receive_minimum.number (), system.nodes[0]->balance (nano::test_genesis_key.pub)); ASSERT_TRUE (system.nodes[0]->balance (key2.pub).is_zero ()); - system.deadline_set (10s); - while (system.nodes[0]->balance (key2.pub).is_zero ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, !system.nodes[0]->balance (key2.pub).is_zero ()); } TEST (node, send_single_observing_peer) @@ -151,11 +143,7 @@ TEST (node, send_single_observing_peer) ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); ASSERT_EQ (std::numeric_limits::max () - system.nodes[0]->config.receive_minimum.number (), system.nodes[0]->balance (nano::test_genesis_key.pub)); ASSERT_TRUE (system.nodes[0]->balance (key2.pub).is_zero ()); - system.deadline_set (10s); - while (std::any_of (system.nodes.begin (), system.nodes.end (), [&](std::shared_ptr const & node_a) { return node_a->balance (key2.pub).is_zero (); })) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, std::all_of (system.nodes.begin (), system.nodes.end (), [&](std::shared_ptr const & node_a) { return !node_a->balance (key2.pub).is_zero (); })); } TEST (node, send_single_many_peers) @@ -167,11 +155,7 @@ TEST (node, send_single_many_peers) ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); ASSERT_EQ (std::numeric_limits::max () - system.nodes[0]->config.receive_minimum.number (), system.nodes[0]->balance (nano::test_genesis_key.pub)); ASSERT_TRUE (system.nodes[0]->balance (key2.pub).is_zero ()); - system.deadline_set (3.5min); - while (std::any_of (system.nodes.begin (), system.nodes.end (), [&](std::shared_ptr const & node_a) { return node_a->balance (key2.pub).is_zero (); })) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (3.5min, std::all_of (system.nodes.begin (), system.nodes.end (), [&](std::shared_ptr const & node_a) { return !node_a->balance (key2.pub).is_zero (); })); system.stop (); for (auto node : system.nodes) { @@ -211,11 +195,7 @@ TEST (node, send_out_of_order) node1.process_active (send3); node1.process_active (send2); node1.process_active (send1); - system.deadline_set (10s); - while (std::any_of (system.nodes.begin (), system.nodes.end (), [&](std::shared_ptr const & node_a) { return node_a->balance (nano::test_genesis_key.pub) != nano::genesis_amount - node1.config.receive_minimum.number () * 3; })) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, std::all_of (system.nodes.begin (), system.nodes.end (), [&](std::shared_ptr const & node_a) { return node_a->balance (nano::test_genesis_key.pub) == nano::genesis_amount - node1.config.receive_minimum.number () * 3; })); } TEST (node, quick_confirm) @@ -235,11 +215,7 @@ TEST (node, quick_confirm) .work (*system.work.generate (previous)) .build_shared (); node1.process_active (send); - system.deadline_set (10s); - while (node1.balance (key.pub).is_zero ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, !node1.balance (key.pub).is_zero ()); ASSERT_EQ (node1.balance (nano::test_genesis_key.pub), node1.config.online_weight_minimum.number () + 1); ASSERT_EQ (node1.balance (key.pub), genesis_start_balance - (node1.config.online_weight_minimum.number () + 1)); } @@ -261,11 +237,7 @@ TEST (node, node_receive_quorum) .work (*system.work.generate (previous)) .build_shared (); node1.process_active (send); - system.deadline_set (10s); - while (!node1.ledger.block_exists (send->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1.ledger.block_exists (send->hash ())); { nano::lock_guard guard (node1.active.mutex); auto info (node1.active.roots.find (nano::qualified_root (previous, previous))); @@ -302,45 +274,21 @@ TEST (node, auto_bootstrap) system.wallet (0)->insert_adhoc (key2.prv); auto send1 (system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, node0->config.receive_minimum.number ())); ASSERT_NE (nullptr, send1); - system.deadline_set (10s); - while (node0->balance (key2.pub) != node0->config.receive_minimum.number ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node0->balance (key2.pub) == node0->config.receive_minimum.number ()); auto node1 (std::make_shared (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.alarm, system.logging, system.work, node_flags)); ASSERT_FALSE (node1->init_error ()); auto channel (std::make_shared (node1->network.udp_channels, node0->network.endpoint (), node1->network_params.protocol.protocol_version)); node1->network.send_keepalive (channel); node1->start (); system.nodes.push_back (node1); - system.deadline_set (10s); - while (!node1->bootstrap_initiator.in_progress ()) - { - ASSERT_NO_ERROR (system.poll ()); - } - system.deadline_set (10s); - while (node1->balance (key2.pub) != node0->config.receive_minimum.number ()) - { - ASSERT_NO_ERROR (system.poll ()); - } - system.deadline_set (10s); - while (node1->bootstrap_initiator.in_progress ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->bootstrap_initiator.in_progress ()); + ASSERT_TIMELY (10s, node1->balance (key2.pub) == node0->config.receive_minimum.number ()); + ASSERT_TIMELY (10s, !node1->bootstrap_initiator.in_progress ()); ASSERT_TRUE (node1->ledger.block_exists (send1->hash ())); // Wait block receive - system.deadline_set (5s); - while (node1->ledger.cache.block_count < 3) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node1->ledger.cache.block_count == 3); // Confirmation for all blocks - system.deadline_set (5s); - while (node1->ledger.cache.cemented_count < 3) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node1->ledger.cache.cemented_count == 3); auto transaction = node1->store.tx_begin_read (); ASSERT_EQ (node1->ledger.cache.unchecked_count, node1->store.unchecked_count (transaction)); @@ -368,11 +316,7 @@ TEST (node, auto_bootstrap_reverse) node0->network.send_keepalive (channel); node1->start (); system.nodes.push_back (node1); - system.deadline_set (10s); - while (node1->balance (key2.pub) != node0->config.receive_minimum.number ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->balance (key2.pub) == node0->config.receive_minimum.number ()); node1->stop (); } @@ -414,11 +358,7 @@ TEST (node, search_pending) ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, node->config.receive_minimum.number ())); system.wallet (0)->insert_adhoc (key2.prv); ASSERT_FALSE (system.wallet (0)->search_pending ()); - system.deadline_set (10s); - while (node->balance (key2.pub).is_zero ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, !node->balance (key2.pub).is_zero ()); } TEST (node, search_pending_same) @@ -431,11 +371,7 @@ TEST (node, search_pending_same) ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, node->config.receive_minimum.number ())); system.wallet (0)->insert_adhoc (key2.prv); ASSERT_FALSE (system.wallet (0)->search_pending ()); - system.deadline_set (10s); - while (node->balance (key2.pub) != 2 * node->config.receive_minimum.number ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->balance (key2.pub) == 2 * node->config.receive_minimum.number ()); } TEST (node, search_pending_multiple) @@ -447,20 +383,12 @@ TEST (node, search_pending_multiple) system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key3.prv); ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key3.pub, node->config.receive_minimum.number ())); - system.deadline_set (10s); - while (node->balance (key3.pub).is_zero ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, !node->balance (key3.pub).is_zero ()); ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, node->config.receive_minimum.number ())); ASSERT_NE (nullptr, system.wallet (0)->send_action (key3.pub, key2.pub, node->config.receive_minimum.number ())); system.wallet (0)->insert_adhoc (key2.prv); ASSERT_FALSE (system.wallet (0)->search_pending ()); - system.deadline_set (10s); - while (node->balance (key2.pub) != 2 * node->config.receive_minimum.number ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->balance (key2.pub) == 2 * node->config.receive_minimum.number ()); } TEST (node, search_pending_confirmed) @@ -475,11 +403,7 @@ TEST (node, search_pending_confirmed) ASSERT_NE (nullptr, send1); auto send2 (system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, node->config.receive_minimum.number ())); ASSERT_NE (nullptr, send2); - system.deadline_set (10s); - while (!node->active.empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->active.empty ()); bool confirmed (false); system.deadline_set (5s); while (!confirmed) @@ -501,11 +425,7 @@ TEST (node, search_pending_confirmed) auto existing2 (node->active.blocks.find (send2->hash ())); ASSERT_EQ (node->active.blocks.end (), existing2); } - system.deadline_set (10s); - while (node->balance (key2.pub) != 2 * node->config.receive_minimum.number ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->balance (key2.pub) == 2 * node->config.receive_minimum.number ()); } TEST (node, unlock_search) @@ -520,15 +440,8 @@ TEST (node, unlock_search) } system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, node->config.receive_minimum.number ())); - system.deadline_set (10s); - while (node->balance (nano::test_genesis_key.pub) == balance) - { - ASSERT_NO_ERROR (system.poll ()); - } - while (!node->active.empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->balance (nano::test_genesis_key.pub) != balance); + ASSERT_TIMELY (10s, node->active.empty ()); system.wallet (0)->insert_adhoc (key2.prv); { nano::lock_guard lock (system.wallet (0)->store.mutex); @@ -538,11 +451,7 @@ TEST (node, unlock_search) auto transaction (system.wallet (0)->wallets.tx_begin_write ()); ASSERT_FALSE (system.wallet (0)->enter_password (transaction, "")); } - system.deadline_set (10s); - while (node->balance (key2.pub).is_zero ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, !node->balance (key2.pub).is_zero ()); } TEST (node, connect_after_junk) @@ -556,20 +465,12 @@ TEST (node, connect_after_junk) junk_buffer.push_back (0); auto channel1 (std::make_shared (node1->network.udp_channels, node0->network.endpoint (), node1->network_params.protocol.protocol_version)); channel1->send_buffer (nano::shared_const_buffer (std::move (junk_buffer)), nano::stat::detail::bulk_pull, [](boost::system::error_code const &, size_t) {}); - system.deadline_set (10s); - while (node0->stats.count (nano::stat::type::error) == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node0->stats.count (nano::stat::type::error) != 0); node1->start (); system.nodes.push_back (node1); auto channel2 (std::make_shared (node1->network.udp_channels, node0->network.endpoint (), node1->network_params.protocol.protocol_version)); node1->network.send_keepalive (channel2); - system.deadline_set (10s); - while (node1->network.empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, !node1->network.empty ()); node1->stop (); } @@ -1238,11 +1139,7 @@ TEST (node_flags, disable_udp) ASSERT_EQ (0, node2->network.size ()); // Send TCP handshake node1->network.merge_peer (node2->network.endpoint ()); - system.deadline_set (5s); - while (node1->bootstrap.realtime_count != 1 || node2->bootstrap.realtime_count != 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node1->bootstrap.realtime_count == 1 && node2->bootstrap.realtime_count == 1); ASSERT_EQ (1, node1->network.size ()); auto list1 (node1->network.list (2)); ASSERT_EQ (node2->network.endpoint (), list1[0]->get_endpoint ()); @@ -1397,12 +1294,8 @@ TEST (node, fork_keep) ASSERT_TRUE (node1.store.block_exists (transaction0, send1->hash ())); ASSERT_TRUE (node2.store.block_exists (transaction1, send1->hash ())); } - system.deadline_set (1.5min); // Wait until the genesis rep makes a vote - while (votes1->last_votes_size () == 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (1.5min, votes1->last_votes_size () != 1); auto transaction0 (node1.store.tx_begin_read ()); auto transaction1 (node2.store.tx_begin_read ()); // The vote should be in agreement with what we already have. @@ -1767,12 +1660,8 @@ TEST (node, fork_open_flip) lock.unlock (); ASSERT_TRUE (node1.block (open1->hash ()) != nullptr); ASSERT_TRUE (node2.block (open2->hash ()) != nullptr); - system.deadline_set (10s); // Node2 should eventually settle on open1 - while (node2.block (open1->hash ()) == nullptr) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node2.block (open1->hash ())); node2.block_processor.flush (); auto transaction1 (node1.store.tx_begin_read ()); auto transaction2 (node2.store.tx_begin_read ()); @@ -1814,11 +1703,7 @@ TEST (node, fork_no_vote_quorum) } auto block (system.wallet (0)->send_action (nano::test_genesis_key.pub, key1, node1.config.receive_minimum.number ())); ASSERT_NE (nullptr, block); - system.deadline_set (30s); - while (node3.balance (key1) != node1.config.receive_minimum.number () || node2.balance (key1) != node1.config.receive_minimum.number () || node1.balance (key1) != node1.config.receive_minimum.number ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (30s, node3.balance (key1) == node1.config.receive_minimum.number () && node2.balance (key1) == node1.config.receive_minimum.number () && node1.balance (key1) == node1.config.receive_minimum.number ()); ASSERT_EQ (node1.config.receive_minimum.number (), node1.weight (key1)); ASSERT_EQ (node1.config.receive_minimum.number (), node2.weight (key1)); ASSERT_EQ (node1.config.receive_minimum.number (), node3.weight (key1)); @@ -1846,10 +1731,7 @@ TEST (node, fork_no_vote_quorum) } nano::transport::channel_udp channel (node2.network.udp_channels, node3.network.endpoint (), node1.network_params.protocol.protocol_version); channel.send_buffer (nano::shared_const_buffer (std::move (buffer)), nano::stat::detail::confirm_ack); - while (node3.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::in) < 3) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node3.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::in) >= 3); ASSERT_TRUE (node1.latest (nano::test_genesis_key.pub) == send1.hash ()); ASSERT_TRUE (node2.latest (nano::test_genesis_key.pub) == send1.hash ()); ASSERT_TRUE (node3.latest (nano::test_genesis_key.pub) == send1.hash ()); @@ -1876,19 +1758,12 @@ TEST (node, DISABLED_fork_pre_confirm) auto transaction (system.wallet (2)->wallets.tx_begin_write ()); system.wallet (2)->store.representative_set (transaction, key2.pub); } - system.deadline_set (30s); auto block0 (system.wallet (0)->send_action (nano::test_genesis_key.pub, key1.pub, nano::genesis_amount / 3)); ASSERT_NE (nullptr, block0); - while (node0.balance (key1.pub) == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (30s, node0.balance (key1.pub) != 0); auto block1 (system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, nano::genesis_amount / 3)); ASSERT_NE (nullptr, block1); - while (node0.balance (key2.pub) == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (30s, node0.balance (key2.pub) != 0); nano::keypair key3; nano::keypair key4; nano::state_block_builder builder; @@ -2124,11 +1999,7 @@ TEST (node, broadcast_elected) .build_shared (); system.wallet (2)->insert_adhoc (rep_small.prv); node2->process_active (fork1); - system.deadline_set (10s); - while (!node0->ledger.block_exists (fork0->hash ()) || !node1->ledger.block_exists (fork0->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node0->ledger.block_exists (fork0->hash ()) && node1->ledger.block_exists (fork0->hash ())); system.deadline_set (50s); while (!node2->ledger.block_exists (fork0->hash ())) { @@ -2137,11 +2008,7 @@ TEST (node, broadcast_elected) ASSERT_TRUE (node1->ledger.block_exists (fork0->hash ())); ASSERT_NO_ERROR (ec); } - system.deadline_set (5s); - while (node1->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::inactive_conf_height, nano::stat::dir::out) == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node1->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::inactive_conf_height, nano::stat::dir::out) != 0); } } @@ -2192,12 +2059,8 @@ TEST (node, rep_self_vote) ASSERT_EQ (nano::process_result::progress, node0->process (*block0).code); auto & active (node0->active); auto election1 = active.insert (block0); - system.deadline_set (1s); // Wait until representatives are activated & make vote - while (election1.election->last_votes_size () != 3) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (1s, election1.election->last_votes_size () == 3); nano::unique_lock lock (active.mutex); auto & rep_votes (election1.election->last_votes); ASSERT_NE (rep_votes.end (), rep_votes.find (nano::test_genesis_key.pub)); @@ -2393,11 +2256,7 @@ TEST (node, DISABLED_unconfirmed_send) wallet1->insert_adhoc (key0.prv); wallet0->insert_adhoc (nano::test_genesis_key.prv); auto send1 (wallet0->send_action (nano::genesis_account, key0.pub, 2 * nano::Mxrb_ratio)); - system.deadline_set (10s); - while (node1.balance (key0.pub) != 2 * nano::Mxrb_ratio || node1.bootstrap_initiator.in_progress ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1.balance (key0.pub) == 2 * nano::Mxrb_ratio && !node1.bootstrap_initiator.in_progress ()); auto latest (node1.latest (key0.pub)); nano::state_block send2 (key0.pub, latest, nano::genesis_account, nano::Mxrb_ratio, nano::genesis_account, key0.prv, key0.pub, *node0.work_generate_blocking (latest)); { @@ -2405,11 +2264,7 @@ TEST (node, DISABLED_unconfirmed_send) ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, send2).code); } auto send3 (wallet1->send_action (key0.pub, nano::genesis_account, nano::Mxrb_ratio)); - system.deadline_set (10s); - while (node0.balance (nano::genesis_account) != nano::genesis_amount) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node0.balance (nano::genesis_account) == nano::genesis_amount); } // Test that nodes can track nodes that have rep weight for priority broadcasting @@ -2515,11 +2370,7 @@ TEST (node, rep_weight) node.rep_crawler.response (channel0, vote0); node.rep_crawler.response (channel1, vote1); node.rep_crawler.response (channel2, vote2); - system.deadline_set (5s); - while (node.rep_crawler.representative_count () != 2) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node.rep_crawler.representative_count () == 2); // Make sure we get the rep with the most weight first auto reps (node.rep_crawler.representatives (1)); ASSERT_EQ (1, reps.size ()); @@ -2595,21 +2446,14 @@ TEST (node, rep_remove) node.network.udp_channels.insert (endpoint0, node.network_params.protocol.protocol_version); auto vote1 = std::make_shared (keypair1.pub, keypair1.prv, 0, genesis.open); node.rep_crawler.response (channel0, vote1); - system.deadline_set (5s); - while (node.rep_crawler.representative_count () != 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node.rep_crawler.representative_count () == 1); auto reps (node.rep_crawler.representatives (1)); ASSERT_EQ (1, reps.size ()); ASSERT_EQ (node.minimum_principal_weight () * 2, reps[0].weight.number ()); ASSERT_EQ (keypair1.pub, reps[0].account); ASSERT_EQ (*channel0, reps[0].channel_ref ()); // This UDP channel is not reachable and should timeout - while (node.rep_crawler.representative_count () != 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node.rep_crawler.representative_count () == 0); // Add working representative auto node1 = system.add_node (nano::node_config (nano::get_available_port (), system.logging)); system.wallet (1)->insert_adhoc (nano::test_genesis_key.prv); @@ -2617,10 +2461,7 @@ TEST (node, rep_remove) ASSERT_NE (nullptr, channel1); auto vote2 = std::make_shared (nano::test_genesis_key.pub, nano::test_genesis_key.prv, 0, genesis.open); node.rep_crawler.response (channel1, vote2); - while (node.rep_crawler.representative_count () != 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node.rep_crawler.representative_count () == 1); // Add inactive TCP representative channel auto node2 (std::make_shared (system.io_ctx, nano::unique_path (), system.alarm, nano::node_config (nano::get_available_port (), system.logging), system.work)); std::atomic done{ false }; @@ -2630,24 +2471,14 @@ TEST (node, rep_remove) if (auto node_l = node_w.lock ()) { node_l->rep_crawler.response (channel2, vote3); - while (node_l->rep_crawler.representative_count () != 2) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node_l->rep_crawler.representative_count () == 2); done = true; } }); - while (!done) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, done); node2->stop (); // Remove inactive representatives - system.deadline_set (10s); - while (node.rep_crawler.representative_count () != 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node.rep_crawler.representative_count () == 1); reps = node.rep_crawler.representatives (1); ASSERT_EQ (nano::test_genesis_key.pub, reps[0].account); ASSERT_EQ (1, node.network.size ()); @@ -2662,18 +2493,10 @@ TEST (node, rep_connection_close) auto & node2 (*system.nodes[1]); // Add working representative (node 2) system.wallet (1)->insert_adhoc (nano::test_genesis_key.prv); - system.deadline_set (10s); - while (node1.rep_crawler.representative_count () != 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1.rep_crawler.representative_count () == 1); node2.stop (); // Remove representative with closed channel - system.deadline_set (10s); - while (node1.rep_crawler.representative_count () != 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1.rep_crawler.representative_count () == 0); } // Test that nodes can disable representative voting @@ -2693,11 +2516,7 @@ TEST (node, no_voting) wallet1->insert_adhoc (key1.prv); // Broadcast a confirm so others should know this is a rep node wallet1->send_action (nano::test_genesis_key.pub, key1.pub, nano::Mxrb_ratio); - system.deadline_set (10s); - while (!node0.active.empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node0.active.empty ()); ASSERT_EQ (0, node0.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::in)); } @@ -2712,11 +2531,7 @@ TEST (node, send_callback) node0.config.callback_port = 8010; node0.config.callback_target = "/"; ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, node0.config.receive_minimum.number ())); - system.deadline_set (10s); - while (node0.balance (key2.pub).is_zero ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node0.balance (key2.pub).is_zero ()); ASSERT_EQ (std::numeric_limits::max () - node0.config.receive_minimum.number (), node0.balance (nano::test_genesis_key.pub)); } @@ -2879,11 +2694,7 @@ TEST (node, block_confirm) .build_shared (); node1.block_processor.add (send1, nano::seconds_since_epoch ()); node2.block_processor.add (send1_copy, nano::seconds_since_epoch ()); - system.deadline_set (std::chrono::seconds (5)); - while (!node1.ledger.block_exists (send1->hash ()) || !node2.ledger.block_exists (send1_copy->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node1.ledger.block_exists (send1->hash ()) && node2.ledger.block_exists (send1_copy->hash ())); ASSERT_TRUE (node1.ledger.block_exists (send1->hash ())); ASSERT_TRUE (node2.ledger.block_exists (send1_copy->hash ())); auto send2 (std::make_shared (nano::test_genesis_key.pub, send1->hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio * 2, key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *node1.work_generate_blocking (send1->hash ()))); @@ -2897,11 +2708,7 @@ TEST (node, block_confirm) } node1.block_confirm (send2); ASSERT_TRUE (node1.active.list_recently_cemented ().empty ()); - system.deadline_set (10s); - while (node1.active.list_recently_cemented ().empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, !node1.active.list_recently_cemented ().empty ()); } } @@ -2971,11 +2778,7 @@ TEST (node, confirm_quorum) .build_shared (); ASSERT_EQ (nano::process_result::progress, node1.process (*send1).code); system.wallet (0)->send_action (nano::test_genesis_key.pub, nano::test_genesis_key.pub, new_balance.number ()); - system.deadline_set (10s); - while (node1.active.empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, !node1.active.empty ()); nano::lock_guard guard (node1.active.mutex); auto info (node1.active.roots.find (nano::qualified_root (send1->hash (), send1->hash ()))); ASSERT_NE (node1.active.roots.end (), info); @@ -3063,7 +2866,7 @@ TEST (node, local_votes_cache) } for (int i = 0; i < 4; ++i) { - system.poll (node.aggregator.max_delay); + ASSERT_NO_ERROR (system.poll (node.aggregator.max_delay)); } // Make sure a new vote was not generated { @@ -3082,7 +2885,7 @@ TEST (node, local_votes_cache) } for (int i = 0; i < 4; ++i) { - system.poll (node.aggregator.max_delay); + ASSERT_NO_ERROR (system.poll (node.aggregator.max_delay)); } wait_vote_sequence (3); ASSERT_TIMELY (3s, node.votes_cache.find (send1->hash ()).empty ()); @@ -3118,46 +2921,26 @@ TEST (node, local_votes_cache_batch) auto channel (node.network.udp_channels.create (node.network.endpoint ())); // Generates and sends one vote for both hashes which is then cached node.network.process_message (message, channel); - system.deadline_set (3s); - while (node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out) < 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (3s, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out) == 1); ASSERT_EQ (1, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out)); ASSERT_FALSE (node.votes_cache.find (genesis.open->hash ()).empty ()); ASSERT_FALSE (node.votes_cache.find (send1->hash ()).empty ()); // Only one confirm_ack should be sent if all hashes are part of the same vote node.network.process_message (message, channel); - system.deadline_set (3s); - while (node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out) < 2) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (3s, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out) == 2); ASSERT_EQ (2, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out)); // Test when votes are different node.votes_cache.remove (genesis.open->hash ()); node.votes_cache.remove (send1->hash ()); node.network.process_message (nano::confirm_req (genesis.open->hash (), genesis.open->root ()), channel); - system.deadline_set (3s); - while (node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out) < 3) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (3s, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out) == 3); ASSERT_EQ (3, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out)); node.network.process_message (nano::confirm_req (send1->hash (), send1->root ()), channel); - system.deadline_set (3s); - while (node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out) < 4) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (3s, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out) == 4); ASSERT_EQ (4, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out)); // There are two different votes, so both should be sent in response node.network.process_message (message, channel); - system.deadline_set (3s); - while (node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out) < 6) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (3s, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out) == 6); ASSERT_EQ (6, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out)); } @@ -3173,11 +2956,7 @@ TEST (node, local_votes_cache_generate_new_vote) nano::confirm_req message1 (genesis.open); auto channel (node.network.udp_channels.create (node.network.endpoint ())); node.network.process_message (message1, channel); - system.deadline_set (3s); - while (node.votes_cache.find (genesis.open->hash ()).empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (3s, !node.votes_cache.find (genesis.open->hash ()).empty ()); auto votes1 (node.votes_cache.find (genesis.open->hash ())); ASSERT_EQ (1, votes1.size ()); ASSERT_EQ (1, votes1[0]->blocks.size ()); @@ -3203,11 +2982,7 @@ TEST (node, local_votes_cache_generate_new_vote) std::vector> roots_hashes{ std::make_pair (genesis.open->hash (), genesis.open->root ()), std::make_pair (send1->hash (), send1->root ()) }; nano::confirm_req message2 (roots_hashes); node.network.process_message (message2, channel); - system.deadline_set (3s); - while (node.votes_cache.find (send1->hash ()).empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (3s, !node.votes_cache.find (send1->hash ()).empty ()); auto votes2 (node.votes_cache.find (send1->hash ())); ASSERT_EQ (1, votes2.size ()); ASSERT_EQ (1, votes2[0]->blocks.size ()); @@ -3274,35 +3049,18 @@ TEST (node, vote_republish) .work (*system.work.generate (genesis.hash ())) .build_shared (); node1.process_active (send1); - system.deadline_set (5s); - while (!node2.block (send1->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node2.block (send1->hash ())); node1.active.publish (send2); auto vote (std::make_shared (nano::test_genesis_key.pub, nano::test_genesis_key.prv, 0, send2)); ASSERT_TRUE (node1.active.active (*send1)); ASSERT_TRUE (node2.active.active (*send1)); node1.vote_processor.vote (vote, std::make_shared (node1.network.udp_channels, node1.network.endpoint (), node1.network_params.protocol.protocol_version)); - while (!node1.block (send2->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } - while (!node2.block (send2->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1.block (send2->hash ())); + ASSERT_TIMELY (10s, node2.block (send2->hash ())); ASSERT_FALSE (node1.block (send1->hash ())); ASSERT_FALSE (node2.block (send1->hash ())); - system.deadline_set (5s); - while (node2.balance (key2.pub) != node1.config.receive_minimum.number () * 2) - { - ASSERT_NO_ERROR (system.poll ()); - } - while (node1.balance (key2.pub) != node1.config.receive_minimum.number () * 2) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node2.balance (key2.pub) == node1.config.receive_minimum.number () * 2); + ASSERT_TIMELY (10s, node1.balance (key2.pub) == node1.config.receive_minimum.number () * 2); } namespace nano @@ -3330,11 +3088,7 @@ TEST (node, vote_by_hash_bundle) // Verify that bundling occurs. While reaching 12 should be common on most hardware in release mode, // we set this low enough to allow the test to pass on CI/with santitizers. - system.deadline_set (20s); - while (max_hashes.load () < 3) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (20s, max_hashes.load () >= 3); } } @@ -3372,11 +3126,7 @@ TEST (node, vote_by_hash_republish) .work (*system.work.generate (genesis.hash ())) .build_shared (); node1.process_active (send1); - system.deadline_set (5s); - while (!node2.block (send1->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node2.block (send1->hash ())); node1.active.publish (send2); std::vector vote_blocks; vote_blocks.push_back (send2->hash ()); @@ -3384,25 +3134,12 @@ TEST (node, vote_by_hash_republish) ASSERT_TRUE (node1.active.active (*send1)); ASSERT_TRUE (node2.active.active (*send1)); node1.vote_processor.vote (vote, std::make_shared (node1.network.udp_channels, node1.network.endpoint (), node1.network_params.protocol.protocol_version)); - while (!node1.block (send2->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } - while (!node2.block (send2->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1.block (send2->hash ())); + ASSERT_TIMELY (10s, node2.block (send2->hash ())); ASSERT_FALSE (node1.block (send1->hash ())); ASSERT_FALSE (node2.block (send1->hash ())); - system.deadline_set (5s); - while (node2.balance (key2.pub) != node1.config.receive_minimum.number () * 2) - { - ASSERT_NO_ERROR (system.poll ()); - } - while (node1.balance (key2.pub) != node1.config.receive_minimum.number () * 2) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node2.balance (key2.pub) == node1.config.receive_minimum.number () * 2); + ASSERT_TIMELY (10s, node1.balance (key2.pub) == node1.config.receive_minimum.number () * 2); } } @@ -3431,11 +3168,7 @@ TEST (node, vote_by_hash_epoch_block_republish) .work (*system.work.generate (genesis.hash ())) .build_shared (); node1.process_active (send1); - system.deadline_set (5s); - while (!node2.block (send1->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node2.block (send1->hash ())); node1.active.publish (epoch1); std::vector vote_blocks; vote_blocks.push_back (epoch1->hash ()); @@ -3443,14 +3176,8 @@ TEST (node, vote_by_hash_epoch_block_republish) ASSERT_TRUE (node1.active.active (*send1)); ASSERT_TRUE (node2.active.active (*send1)); node1.vote_processor.vote (vote, std::make_shared (node1.network.udp_channels, node1.network.endpoint (), node1.network_params.protocol.protocol_version)); - while (!node1.block (epoch1->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } - while (!node2.block (epoch1->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1.block (epoch1->hash ())); + ASSERT_TIMELY (10s, node2.block (epoch1->hash ())); ASSERT_FALSE (node1.block (send1->hash ())); ASSERT_FALSE (node2.block (send1->hash ())); } @@ -3533,11 +3260,7 @@ TEST (node, epoch_conflict_confirm) } node0->process_active (change); node0->process_active (epoch_open); - system.deadline_set (5s); - while (!node0->block (change->hash ()) || !node0->block (epoch_open->hash ()) || !node1->block (change->hash ()) || !node1->block (epoch_open->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node0->block (change->hash ()) && node0->block (epoch_open->hash ()) && node1->block (change->hash ()) && node1->block (epoch_open->hash ())); nano::blocks_confirm (*node0, { change, epoch_open }); ASSERT_EQ (2, node0->active.size ()); { @@ -3546,11 +3269,7 @@ TEST (node, epoch_conflict_confirm) ASSERT_TRUE (node0->active.blocks.find (epoch_open->hash ()) != node0->active.blocks.end ()); } system.wallet (1)->insert_adhoc (nano::test_genesis_key.prv); - system.deadline_set (5s); - while (!node0->active.empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node0->active.empty ()); { auto transaction (node0->store.tx_begin_read ()); ASSERT_TRUE (node0->ledger.store.block_exists (transaction, change->hash ())); @@ -3593,25 +3312,15 @@ TEST (node, fork_invalid_block_signature) auto vote_corrupt (std::make_shared (nano::test_genesis_key.pub, nano::test_genesis_key.prv, 0, send2_corrupt)); node1.process_active (send1); - system.deadline_set (5s); - while (!node1.block (send1->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node1.block (send1->hash ())); // Send the vote with the corrupt block signature node2.network.flood_vote (vote_corrupt, 1.0f); // Wait for the rollback ASSERT_TIMELY (5s, node1.stats.count (nano::stat::type::rollback, nano::stat::detail::all)); // Send the vote with the correct block node2.network.flood_vote (vote, 1.0f); - while (node1.block (send1->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } - while (!node1.block (send2->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, !node1.block (send1->hash ())); + ASSERT_TIMELY (10s, node1.block (send2->hash ())); ASSERT_EQ (node1.block (send2->hash ())->block_signature (), send2->block_signature ()); } @@ -3874,11 +3583,7 @@ TEST (node, block_processor_full) ASSERT_FALSE (node.block_processor.full ()); node.block_processor.add (send3); // Block processor may be not full during state blocks signatures verification - system.deadline_set (2s); - while (!node.block_processor.full ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (2s, node.block_processor.full ()); } TEST (node, block_processor_half_full) @@ -3924,11 +3629,7 @@ TEST (node, block_processor_half_full) ASSERT_FALSE (node.block_processor.half_full ()); node.block_processor.add (send3); // Block processor may be not half_full during state blocks signatures verification - system.deadline_set (2s); - while (!node.block_processor.half_full ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (2s, node.block_processor.half_full ()); ASSERT_FALSE (node.block_processor.full ()); } @@ -3974,11 +3675,7 @@ TEST (node, confirm_back) vote_blocks.push_back (send2->hash ()); auto vote (std::make_shared (nano::test_genesis_key.pub, nano::test_genesis_key.prv, 0, vote_blocks)); node.vote_processor.vote_blocking (vote, std::make_shared (node.network.udp_channels, node.network.endpoint (), node.network_params.protocol.protocol_version)); - system.deadline_set (10s); - while (!node.active.empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node.active.empty ()); } TEST (node, peers) @@ -4003,17 +3700,9 @@ TEST (node, peers) } node2->start (); - system.deadline_set (10s); - while (node2->network.empty () || node1->network.empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, !node2->network.empty () && !node1->network.empty ()) // Wait to finish TCP node ID handshakes - system.deadline_set (10s); - while (node1->bootstrap.realtime_count == 0 || node2->bootstrap.realtime_count == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->bootstrap.realtime_count != 0 && node2->bootstrap.realtime_count != 0); // Confirm that the peers match with the endpoints we are expecting ASSERT_EQ (1, node1->network.size ()); auto list1 (node1->network.list (2)); @@ -4026,11 +3715,7 @@ TEST (node, peers) // Stop the peer node and check that it is removed from the store node1->stop (); - system.deadline_set (10s); - while (node2->network.size () == 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node2->network.size () != 1); ASSERT_TRUE (node2->network.empty ()); @@ -4060,11 +3745,7 @@ TEST (node, peer_cache_restart) store.peer_put (transaction, endpoint_key); } node2->start (); - system.deadline_set (10s); - while (node2->network.empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, !node2->network.empty ()); // Confirm that the peers match with the endpoints we are expecting auto list (node2->network.list (2)); ASSERT_EQ (node1->network.endpoint (), list[0]->get_endpoint ()); @@ -4087,11 +3768,7 @@ TEST (node, peer_cache_restart) ASSERT_EQ (store.peer_count (transaction), 1); ASSERT_TRUE (store.peer_exists (transaction, endpoint_key)); } - system.deadline_set (10s); - while (node3->network.empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, !node3->network.empty ()); // Confirm that the peers match with the endpoints we are expecting auto list (node3->network.list (2)); ASSERT_EQ (node1->network.endpoint (), list[0]->get_endpoint ()); @@ -4222,19 +3899,11 @@ TEST (node, bidirectional_tcp) .build_shared (); node1->process_active (send1); node1->block_processor.flush (); - system.deadline_set (5s); - while (!node1->ledger.block_exists (send1->hash ()) || !node2->ledger.block_exists (send1->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->ledger.block_exists (send1->hash ()) && node2->ledger.block_exists (send1->hash ())); // Test block confirmation from node 1 (add representative to node 1) system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); // Wait to find new reresentative - system.deadline_set (10s); - while (node2->rep_crawler.representative_count () == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node2->rep_crawler.representative_count () != 0); /* Wait for confirmation To check connection we need only node 2 confirmation status Node 1 election can be unconfirmed because representative private key was inserted after election start (and node 2 isn't flooding new votes to principal representatives) */ @@ -4264,19 +3933,11 @@ TEST (node, bidirectional_tcp) .build_shared (); node2->process_active (send2); node2->block_processor.flush (); - system.deadline_set (5s); - while (!node1->ledger.block_exists (send2->hash ()) || !node2->ledger.block_exists (send2->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->ledger.block_exists (send2->hash ()) && node2->ledger.block_exists (send2->hash ())); // Test block confirmation from node 2 (add representative to node 2) system.wallet (1)->insert_adhoc (nano::test_genesis_key.prv); // Wait to find changed reresentative - system.deadline_set (10s); - while (node1->rep_crawler.representative_count () == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1->rep_crawler.representative_count () != 0); /* Wait for confirmation To check connection we need only node 1 confirmation status Node 2 election can be unconfirmed because representative private key was inserted after election start (and node 1 isn't flooding new votes to principal representatives) */ @@ -4416,11 +4077,7 @@ TEST (active_difficulty, recalculate_work) auto multiplier1 = nano::difficulty::to_multiplier (send1->difficulty (), node1.network_params.network.publish_thresholds.epoch_1); // Process as local block node1.process_active (send1); - system.deadline_set (2s); - while (node1.active.empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (2s, !node1.active.empty ()); auto sum (std::accumulate (node1.active.multipliers_cb.begin (), node1.active.multipliers_cb.end (), double(0))); ASSERT_EQ (node1.active.active_difficulty (), nano::difficulty::from_multiplier (sum / node1.active.multipliers_cb.size (), node1.network_params.network.publish_thresholds.epoch_1)); nano::unique_lock lock (node1.active.mutex); diff --git a/nano/core_test/telemetry.cpp b/nano/core_test/telemetry.cpp index c300ca01d7..043d2f8d37 100644 --- a/nano/core_test/telemetry.cpp +++ b/nano/core_test/telemetry.cpp @@ -233,11 +233,7 @@ TEST (telemetry, basic) done = true; }); - system.deadline_set (10s); - while (!done) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, done); } // Check the metrics are correct @@ -252,11 +248,7 @@ TEST (telemetry, basic) done = true; }); - system.deadline_set (10s); - while (!done) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, done); } // Wait the cache period and check cache is not used @@ -269,11 +261,7 @@ TEST (telemetry, basic) done = true; }); - system.deadline_set (10s); - while (!done) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, done); } TEST (telemetry, receive_from_non_listening_channel) @@ -305,11 +293,7 @@ TEST (telemetry, over_udp) done = true; }); - system.deadline_set (10s); - while (!done) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, done); // Check channels are indeed udp ASSERT_EQ (1, node_client->network.size ()); @@ -335,11 +319,7 @@ TEST (telemetry, invalid_channel) done = true; }); - system.deadline_set (10s); - while (!done) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, done); } TEST (telemetry, blocking_request) @@ -401,11 +381,7 @@ TEST (telemetry, disconnects) done = true; }); - system.deadline_set (10s); - while (!done) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, done); } TEST (telemetry, dos_tcp) @@ -426,11 +402,7 @@ TEST (telemetry, dos_tcp) ASSERT_FALSE (ec); }); - system.deadline_set (10s); - while (1 != node_server->stats.count (nano::stat::type::message, nano::stat::detail::telemetry_req, nano::stat::dir::in)) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, 1 == node_server->stats.count (nano::stat::type::message, nano::stat::detail::telemetry_req, nano::stat::dir::in)); auto orig = std::chrono::steady_clock::now (); for (int i = 0; i < 10; ++i) @@ -440,11 +412,7 @@ TEST (telemetry, dos_tcp) }); } - system.deadline_set (10s); - while ((nano::telemetry_cache_cutoffs::test + orig) > std::chrono::steady_clock::now ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, (nano::telemetry_cache_cutoffs::test + orig) <= std::chrono::steady_clock::now ()); // Should process no more telemetry_req messages ASSERT_EQ (1, node_server->stats.count (nano::stat::type::message, nano::stat::detail::telemetry_req, nano::stat::dir::in)); @@ -477,11 +445,7 @@ TEST (telemetry, dos_udp) ASSERT_FALSE (ec); }); - system.deadline_set (20s); - while (1 != node_server->stats.count (nano::stat::type::message, nano::stat::detail::telemetry_req, nano::stat::dir::in)) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (20s, 1 == node_server->stats.count (nano::stat::type::message, nano::stat::detail::telemetry_req, nano::stat::dir::in)); auto orig = std::chrono::steady_clock::now (); for (int i = 0; i < 10; ++i) @@ -491,11 +455,7 @@ TEST (telemetry, dos_udp) }); } - system.deadline_set (20s); - while ((nano::telemetry_cache_cutoffs::test + orig) > std::chrono::steady_clock::now ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (20s, (nano::telemetry_cache_cutoffs::test + orig) <= std::chrono::steady_clock::now ()); // Should process no more telemetry_req messages ASSERT_EQ (1, node_server->stats.count (nano::stat::type::message, nano::stat::detail::telemetry_req, nano::stat::dir::in)); @@ -530,11 +490,7 @@ TEST (telemetry, disable_metrics) done = true; }); - system.deadline_set (10s); - while (!done) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, done); // It should still be able to receive metrics though done = false; @@ -545,11 +501,7 @@ TEST (telemetry, disable_metrics) done = true; }); - system.deadline_set (10s); - while (!done) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, done); } namespace nano diff --git a/nano/core_test/vote_processor.cpp b/nano/core_test/vote_processor.cpp index a6317f7636..1ffc13d24b 100644 --- a/nano/core_test/vote_processor.cpp +++ b/nano/core_test/vote_processor.cpp @@ -158,11 +158,7 @@ TEST (vote_processor, weights) system.wallet (0)->send_sync (nano::test_genesis_key.pub, key2.pub, level2); // Wait for representatives - system.deadline_set (10s); - while (node.ledger.cache.rep_weights.get_rep_amounts ().size () != 4) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node.ledger.cache.rep_weights.get_rep_amounts ().size () == 4); node.vote_processor.calculate_weights (); ASSERT_EQ (node.vote_processor.representatives_1.end (), node.vote_processor.representatives_1.find (key0.pub)); diff --git a/nano/core_test/wallet.cpp b/nano/core_test/wallet.cpp index add7e69e33..15f46241ae 100644 --- a/nano/core_test/wallet.cpp +++ b/nano/core_test/wallet.cpp @@ -198,12 +198,8 @@ TEST (wallet, send_async) nano::system system (1); system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); nano::keypair key2; - boost::thread thread ([&system]() { - system.deadline_set (10s); - while (!system.nodes[0]->balance (nano::test_genesis_key.pub).is_zero ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + std::thread thread ([&system]() { + ASSERT_TIMELY (10s, system.nodes[0]->balance (nano::test_genesis_key.pub).is_zero ()); }); std::atomic success (false); system.wallet (0)->send_async (nano::test_genesis_key.pub, key2.pub, std::numeric_limits::max (), [&success](std::shared_ptr block_a) { ASSERT_NE (nullptr, block_a); success = true; }); @@ -670,12 +666,8 @@ TEST (wallet, work_generate) } nano::keypair key; auto block (wallet->send_action (nano::test_genesis_key.pub, key.pub, 100)); - system.deadline_set (10s); auto transaction (node1.store.tx_begin_read ()); - while (node1.ledger.account_balance (transaction, nano::test_genesis_key.pub) == amount1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1.ledger.account_balance (transaction, nano::test_genesis_key.pub) != amount1); system.deadline_set (10s); auto again (true); while (again) @@ -1219,11 +1211,7 @@ TEST (work_watcher, propagate) auto & node_passive = *system.add_node (node_config); nano::keypair key; auto const block (wallet.send_action (nano::test_genesis_key.pub, key.pub, 100)); - system.deadline_set (5s); - while (!node_passive.ledger.block_exists (block->hash ())) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node_passive.ledger.block_exists (block->hash ())); auto const multiplier (nano::normalized_multiplier (nano::difficulty::to_multiplier (block->difficulty (), nano::work_threshold (block->work_version (), nano::block_details (nano::epoch::epoch_0, false, false, false))), node.network_params.network.publish_thresholds.epoch_1)); auto updated_multiplier{ multiplier }; auto propagated_multiplier{ multiplier }; @@ -1270,11 +1258,7 @@ TEST (work_watcher, removed_after_win) ASSERT_EQ (0, wallet.wallets.watcher->size ()); auto const block1 (wallet.send_action (nano::test_genesis_key.pub, key.pub, 100)); ASSERT_EQ (1, wallet.wallets.watcher->size ()); - system.deadline_set (5s); - while (node.wallets.watcher->is_watched (block1->qualified_root ())) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, !node.wallets.watcher->is_watched (block1->qualified_root ())); ASSERT_EQ (0, node.wallets.watcher->size ()); } @@ -1297,11 +1281,7 @@ TEST (work_watcher, removed_after_lose) auto vote (std::make_shared (nano::test_genesis_key.pub, nano::test_genesis_key.prv, 0, fork1)); nano::confirm_ack message (vote); node.network.process_message (message, nullptr); - system.deadline_set (5s); - while (node.wallets.watcher->is_watched (block1->qualified_root ())) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, !node.wallets.watcher->is_watched (block1->qualified_root ())); ASSERT_EQ (0, node.wallets.watcher->size ()); } @@ -1367,11 +1347,7 @@ TEST (work_watcher, cancel) node.active.update_active_multiplier (lock); } // Wait for work generation to start - system.deadline_set (5s); - while (0 == node.work.size ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, 0 != node.work.size ()); // Cancel the ongoing work ASSERT_EQ (1, node.work.size ()); node.work.cancel (block1->root ()); diff --git a/nano/core_test/wallets.cpp b/nano/core_test/wallets.cpp index a8521ff881..9ff928a473 100644 --- a/nano/core_test/wallets.cpp +++ b/nano/core_test/wallets.cpp @@ -164,11 +164,7 @@ TEST (wallets, reload) auto wallet (node.node->wallets.create (one)); ASSERT_NE (wallet, nullptr); } - system.deadline_set (5s); - while (node1.wallets.open (one) == nullptr) - { - system.poll (); - } + ASSERT_TIMELY (5s, node1.wallets.open (one) != nullptr); ASSERT_EQ (2, node1.wallets.items.size ()); } diff --git a/nano/core_test/websocket.cpp b/nano/core_test/websocket.cpp index de0559d286..fe5d4a0cb9 100644 --- a/nano/core_test/websocket.cpp +++ b/nano/core_test/websocket.cpp @@ -45,11 +45,7 @@ TEST (websocket, subscription_edge) }); auto future = std::async (std::launch::async, task); - system.deadline_set (5s); - while (future.wait_for (0s) != std::future_status::ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, future.wait_for (0s) == std::future_status::ready); } // Test client subscribing to changes in active_multiplier @@ -81,11 +77,7 @@ TEST (websocket, active_difficulty) }); auto future = std::async (std::launch::async, task); - system.deadline_set (5s); - while (!ack_ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, ack_ready); // Fake history records and force a trended_active_multiplier change { @@ -94,11 +86,7 @@ TEST (websocket, active_difficulty) node1->active.update_active_multiplier (lock); } - system.deadline_set (5s); - while (future.wait_for (0s) != std::future_status::ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, future.wait_for (0s) == std::future_status::ready); // Check active_difficulty response boost::optional response = future.get (); @@ -153,11 +141,7 @@ TEST (websocket, confirmation) }); auto future = std::async (std::launch::async, task); - system.deadline_set (5s); - while (!ack_ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, ack_ready); nano::keypair key; system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); @@ -171,11 +155,7 @@ TEST (websocket, confirmation) node1->process_active (send); } - system.deadline_set (5s); - while (!unsubscribed) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, unsubscribed); // Quick confirm a state block { @@ -185,11 +165,7 @@ TEST (websocket, confirmation) node1->process_active (send); } - system.deadline_set (5s); - while (future.wait_for (0s) != std::future_status::ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, future.wait_for (0s) == std::future_status::ready); } // Tests getting notification of an erased election @@ -212,11 +188,7 @@ TEST (websocket, stopped_election) }); auto future = std::async (std::launch::async, task); - system.deadline_set (5s); - while (!ack_ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, ack_ready); // Create election, then erase it, causing a websocket message to be emitted nano::keypair key1; @@ -228,11 +200,7 @@ TEST (websocket, stopped_election) node1->block_processor.flush (); node1->active.erase (*send1); - system.deadline_set (5s); - while (future.wait_for (0s) != std::future_status::ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, future.wait_for (0s) == std::future_status::ready); auto response = future.get (); ASSERT_TRUE (response); @@ -264,11 +232,7 @@ TEST (websocket, confirmation_options) }); auto future1 = std::async (std::launch::async, task1); - system.deadline_set (5s); - while (!ack_ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, ack_ready); // Confirm a state block for an in-wallet account system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); @@ -283,11 +247,7 @@ TEST (websocket, confirmation_options) previous = send->hash (); } - system.deadline_set (5s); - while (future1.wait_for (0s) != std::future_status::ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, future1.wait_for (0s) == std::future_status::ready); ack_ready = false; auto task2 = ([&ack_ready, config, &node1]() { @@ -300,11 +260,7 @@ TEST (websocket, confirmation_options) }); auto future2 = std::async (std::launch::async, task2); - system.deadline_set (5s); - while (!ack_ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, ack_ready); // Quick-confirm another block { @@ -314,11 +270,7 @@ TEST (websocket, confirmation_options) previous = send->hash (); } - system.deadline_set (5s); - while (future2.wait_for (0s) != std::future_status::ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, future2.wait_for (0s) == std::future_status::ready); auto response2 = future2.get (); ASSERT_TRUE (response2); @@ -358,11 +310,7 @@ TEST (websocket, confirmation_options) }); auto future3 = std::async (std::launch::async, task3); - system.deadline_set (5s); - while (!ack_ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, ack_ready); // Confirm a legacy block // When filtering options are enabled, legacy blocks are always filtered @@ -373,11 +321,7 @@ TEST (websocket, confirmation_options) previous = send->hash (); } - system.deadline_set (5s); - while (future1.wait_for (0s) != std::future_status::ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, future1.wait_for (0s) == std::future_status::ready); } // Tests updating options of block confirmations @@ -415,11 +359,7 @@ TEST (websocket, confirmation_options_update) auto future = std::async (std::launch::async, task); // Wait for update acknowledgement - system.deadline_set (5s); - while (!added) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, added); // Confirm a block system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); @@ -430,22 +370,14 @@ TEST (websocket, confirmation_options_update) node1->process_active (send); // Wait for delete acknowledgement - system.deadline_set (5s); - while (!deleted) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, deleted); // Confirm another block previous = send->hash (); auto send2 (std::make_shared (nano::test_genesis_key.pub, previous, nano::test_genesis_key.pub, nano::genesis_amount - 2 * nano::Gxrb_ratio, key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (previous))); node1->process_active (send2); - system.deadline_set (5s); - while (future.wait_for (0s) != std::future_status::ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, future.wait_for (0s) == std::future_status::ready); } // Subscribes to votes, sends a block and awaits websocket notification of a vote arrival @@ -468,11 +400,7 @@ TEST (websocket, vote) }); auto future = std::async (std::launch::async, task); - system.deadline_set (5s); - while (!ack_ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, ack_ready); // Quick-confirm a block nano::keypair key; @@ -481,11 +409,7 @@ TEST (websocket, vote) auto send (std::make_shared (nano::test_genesis_key.pub, previous, nano::test_genesis_key.pub, nano::genesis_amount - (node1->config.online_weight_minimum.number () + 1), key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (previous))); node1->process_active (send); - system.deadline_set (5s); - while (future.wait_for (0s) != std::future_status::ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, future.wait_for (0s) == std::future_status::ready); auto response = future.get (); ASSERT_TRUE (response); @@ -516,11 +440,7 @@ TEST (websocket, vote_options_type) }); auto future = std::async (std::launch::async, task); - system.deadline_set (5s); - while (!ack_ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, ack_ready); // Custom made votes for simplicity nano::genesis genesis; @@ -529,11 +449,7 @@ TEST (websocket, vote_options_type) auto msg (builder.vote_received (vote, nano::vote_code::replay)); node1->websocket_server->broadcast (msg); - system.deadline_set (5s); - while (future.wait_for (0s) != std::future_status::ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, future.wait_for (0s) == std::future_status::ready); auto response = future.get (); ASSERT_TRUE (response); @@ -573,11 +489,7 @@ TEST (websocket, vote_options_representatives) }); auto future1 = std::async (std::launch::async, task1); - system.deadline_set (5s); - while (!ack_ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, ack_ready); // Quick-confirm a block nano::keypair key; @@ -592,11 +504,7 @@ TEST (websocket, vote_options_representatives) }; confirm_block (); - system.deadline_set (5s); - while (future1.wait_for (0s) != std::future_status::ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, future1.wait_for (0s) == std::future_status::ready); ack_ready = false; auto task2 = ([&ack_ready, config, &node1]() { @@ -612,20 +520,12 @@ TEST (websocket, vote_options_representatives) auto future2 = std::async (std::launch::async, task2); // Wait for the subscription to be acknowledged - system.deadline_set (5s); - while (!ack_ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, ack_ready); // Confirm another block confirm_block (); - system.deadline_set (5s); - while (future2.wait_for (0s) != std::future_status::ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, future2.wait_for (0s) == std::future_status::ready); } // Test client subscribing to notifications for work generation @@ -652,11 +552,7 @@ TEST (websocket, work) auto future = std::async (std::launch::async, task); // Wait for acknowledge - system.deadline_set (5s); - while (!ack_ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, ack_ready); ASSERT_EQ (1, node1->websocket_server->subscriber_count (nano::websocket::topic::work)); // Generate work @@ -665,11 +561,7 @@ TEST (websocket, work) ASSERT_TRUE (work.is_initialized ()); // Wait for the work notification - system.deadline_set (5s); - while (future.wait_for (0s) != std::future_status::ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, future.wait_for (0s) == std::future_status::ready); // Check the work notification message auto response = future.get (); @@ -730,22 +622,14 @@ TEST (websocket, bootstrap) auto future = std::async (std::launch::async, task); // Wait for acknowledge - system.deadline_set (5s); - while (!ack_ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, ack_ready); // Start bootstrap attempt node1->bootstrap_initiator.bootstrap (true, "123abc"); ASSERT_NE (nullptr, node1->bootstrap_initiator.current_attempt ()); // Wait for the bootstrap notification - system.deadline_set (5s); - while (future.wait_for (0s) != std::future_status::ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, future.wait_for (0s) == std::future_status::ready); // Check the bootstrap notification message auto response = future.get (); @@ -762,11 +646,7 @@ TEST (websocket, bootstrap) ASSERT_EQ (contents.get ("mode"), "legacy"); // Wait for bootstrap finish - system.deadline_set (5s); - while (node1->bootstrap_initiator.in_progress ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, !node1->bootstrap_initiator.in_progress ()); } TEST (websocket, bootstrap_exited) @@ -794,11 +674,7 @@ TEST (websocket, bootstrap_exited) }); // Wait for bootstrap start - system.deadline_set (5s); - while (!bootstrap_started) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, bootstrap_started); // Subscribe to bootstrap and wait for response asynchronously std::atomic ack_ready{ false }; @@ -813,20 +689,12 @@ TEST (websocket, bootstrap_exited) auto future = std::async (std::launch::async, task); // Wait for acknowledge - system.deadline_set (5s); - while (!ack_ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, ack_ready); // Wait for the bootstrap notification subscribed_completion.increment (); bootstrap_thread.join (); - system.deadline_set (5s); - while (future.wait_for (0s) != std::future_status::ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, future.wait_for (0s) == std::future_status::ready); // Check the bootstrap notification message auto response = future.get (); @@ -861,11 +729,7 @@ TEST (websocket, ws_keepalive) }); auto future = std::async (std::launch::async, task); - system.deadline_set (5s); - while (future.wait_for (0s) != std::future_status::ready) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, future.wait_for (0s) == std::future_status::ready); } // Tests sending telemetry diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index fa2c92c4cd..a0ea2a8bef 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -120,11 +120,7 @@ void reset_confirmation_height (nano::block_store & store, nano::account const & void check_block_response_count (nano::system & system, nano::rpc & rpc, boost::property_tree::ptree & request, uint64_t size_count) { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (size_count, response.json.get_child ("blocks").front ().second.size ()); } @@ -193,11 +189,7 @@ TEST (rpc, account_balance) request.put ("action", "account_balance"); request.put ("account", nano::test_genesis_key.pub.to_account ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string balance_text (response.json.get ("balance")); ASSERT_EQ ("340282366920938463463374607431768211455", balance_text); @@ -221,11 +213,7 @@ TEST (rpc, account_block_count) request.put ("action", "account_block_count"); request.put ("account", nano::test_genesis_key.pub.to_account ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string block_count_text (response.json.get ("block_count")); ASSERT_EQ ("1", block_count_text); @@ -247,11 +235,7 @@ TEST (rpc, account_create) request.put ("action", "account_create"); request.put ("wallet", node->wallets.items.begin ()->first.to_string ()); test_response response0 (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response0.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response0.status != 0); ASSERT_EQ (200, response0.status); auto account_text0 (response0.json.get ("account")); nano::account account0; @@ -260,11 +244,7 @@ TEST (rpc, account_create) constexpr uint64_t max_index (std::numeric_limits::max ()); request.put ("index", max_index); test_response response1 (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response1.status != 0); ASSERT_EQ (200, response1.status); auto account_text1 (response1.json.get ("account")); nano::account account1; @@ -272,11 +252,7 @@ TEST (rpc, account_create) ASSERT_TRUE (system.wallet (0)->exists (account1)); request.put ("index", max_index + 1); test_response response2 (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response2.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response2.status != 0); ASSERT_EQ (200, response2.status); ASSERT_EQ (std::error_code (nano::error_common::invalid_index).message (), response2.json.get ("error")); } @@ -301,11 +277,7 @@ TEST (rpc, account_weight) request.put ("action", "account_weight"); request.put ("account", key.pub.to_account ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string balance_text (response.json.get ("weight")); ASSERT_EQ ("340282366920938463463374607431768211455", balance_text); @@ -331,11 +303,7 @@ TEST (rpc, wallet_contains) request.put ("action", "wallet_contains"); request.put ("account", nano::test_genesis_key.pub.to_account ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string exists_text (response.json.get ("exists")); ASSERT_EQ ("1", exists_text); @@ -360,11 +328,7 @@ TEST (rpc, wallet_doesnt_contain) request.put ("action", "wallet_contains"); request.put ("account", nano::test_genesis_key.pub.to_account ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string exists_text (response.json.get ("exists")); ASSERT_EQ ("0", exists_text); @@ -387,11 +351,7 @@ TEST (rpc, validate_account_number) request.put ("action", "validate_account_number"); request.put ("account", nano::test_genesis_key.pub.to_account ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); std::string exists_text (response.json.get ("valid")); ASSERT_EQ ("1", exists_text); } @@ -416,11 +376,7 @@ TEST (rpc, validate_account_invalid) request.put ("action", "validate_account_number"); request.put ("account", account); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string exists_text (response.json.get ("valid")); ASSERT_EQ ("0", exists_text); @@ -447,18 +403,11 @@ TEST (rpc, send) request.put ("source", nano::test_genesis_key.pub.to_account ()); request.put ("destination", nano::test_genesis_key.pub.to_account ()); request.put ("amount", "100"); - system.deadline_set (10s); - boost::thread thread2 ([&system, node]() { - while (node->balance (nano::test_genesis_key.pub) == nano::genesis_amount) - { - ASSERT_NO_ERROR (system.poll ()); - } + std::thread thread2 ([&system, node]() { + ASSERT_TIMELY (10s, node->balance (nano::test_genesis_key.pub) != nano::genesis_amount); }); test_response response (request, rpc.config.port, system.io_ctx); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); std::string block_text (response.json.get ("block")); nano::block_hash block; @@ -490,17 +439,11 @@ TEST (rpc, send_fail) request.put ("amount", "100"); std::atomic done (false); system.deadline_set (10s); - boost::thread thread2 ([&system, &done]() { - while (!done) - { - ASSERT_NO_ERROR (system.poll ()); - } + std::thread thread2 ([&system, &done]() { + ASSERT_TIMELY (10s, done); }); test_response response (request, rpc.config.port, system.io_ctx); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); done = true; ASSERT_EQ (std::error_code (nano::error_common::account_not_found_wallet).message (), response.json.get ("error")); thread2.join (); @@ -529,20 +472,12 @@ TEST (rpc, send_work) request.put ("amount", "100"); request.put ("work", "1"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (std::error_code (nano::error_common::invalid_work).message (), response.json.get ("error")); request.erase ("work"); request.put ("work", nano::to_string_hex (*node->work_generate_blocking (node->latest (nano::test_genesis_key.pub)))); test_response response2 (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response2.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response2.status != 0); ASSERT_EQ (200, response2.status); std::string block_text (response2.json.get ("block")); nano::block_hash block; @@ -576,11 +511,7 @@ TEST (rpc, send_work_disabled) request.put ("amount", "100"); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (std::error_code (nano::error_common::disabled_work_generation).message (), response.json.get ("error")); } @@ -609,11 +540,7 @@ TEST (rpc, send_idempotent) request.put ("amount", (nano::genesis_amount - (nano::genesis_amount / 4)).convert_to ()); request.put ("id", "123abc"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string block_text (response.json.get ("block")); nano::block_hash block; @@ -621,11 +548,7 @@ TEST (rpc, send_idempotent) ASSERT_TRUE (node->ledger.block_exists (block)); ASSERT_EQ (node->balance (nano::test_genesis_key.pub), nano::genesis_amount / 4); test_response response2 (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response2.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response2.status != 0); ASSERT_EQ (200, response2.status); ASSERT_EQ ("", response2.json.get ("error", "")); ASSERT_EQ (block_text, response2.json.get ("block")); @@ -633,11 +556,7 @@ TEST (rpc, send_idempotent) request.erase ("id"); request.put ("id", "456def"); test_response response3 (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response3.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response3.status != 0); ASSERT_EQ (200, response3.status); ASSERT_EQ (std::error_code (nano::error_common::insufficient_balance).message (), response3.json.get ("error")); } @@ -679,11 +598,7 @@ TEST (rpc, send_epoch_2) request.put ("work", nano::to_string_hex (insufficient)); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::error_code ec (nano::error_common::invalid_work); ASSERT_EQ (1, response.json.count ("error")); @@ -706,11 +621,8 @@ TEST (rpc, stop) boost::property_tree::ptree request; request.put ("action", "stop"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - }; + ASSERT_TIMELY (5s, response.status != 0); + ; } TEST (rpc, wallet_add) @@ -735,11 +647,7 @@ TEST (rpc, wallet_add) request.put ("action", "wallet_add"); request.put ("key", key_text); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string account_text1 (response.json.get ("account")); ASSERT_EQ (account_text1, key1.pub.to_account ()); @@ -764,11 +672,7 @@ TEST (rpc, wallet_password_valid) request.put ("wallet", wallet); request.put ("action", "password_valid"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string account_text1 (response.json.get ("valid")); ASSERT_EQ (account_text1, "1"); @@ -793,11 +697,7 @@ TEST (rpc, wallet_password_change) request.put ("action", "password_change"); request.put ("password", "test"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string account_text1 (response.json.get ("changed")); ASSERT_EQ (account_text1, "1"); @@ -837,11 +737,7 @@ TEST (rpc, wallet_password_enter) request.put ("action", "password_enter"); request.put ("password", ""); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string account_text1 (response.json.get ("valid")); ASSERT_EQ (account_text1, "1"); @@ -865,11 +761,7 @@ TEST (rpc, wallet_representative) request.put ("wallet", wallet); request.put ("action", "wallet_representative"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string account_text1 (response.json.get ("representative")); ASSERT_EQ (account_text1, nano::genesis_account.to_account ()); @@ -895,11 +787,7 @@ TEST (rpc, wallet_representative_set) request.put ("action", "wallet_representative_set"); request.put ("representative", key.pub.to_account ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto transaction (node->wallets.tx_begin_read ()); ASSERT_EQ (key.pub, node->wallets.items.begin ()->second->store.representative (transaction)); @@ -927,11 +815,7 @@ TEST (rpc, wallet_representative_set_force) request.put ("representative", key.pub.to_account ()); request.put ("update_existing_accounts", true); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); { auto transaction (node->wallets.tx_begin_read ()); @@ -971,11 +855,7 @@ TEST (rpc, account_list) request.put ("wallet", wallet); request.put ("action", "account_list"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & accounts_node (response.json.get_child ("accounts")); std::vector accounts; @@ -1012,11 +892,7 @@ TEST (rpc, wallet_key_valid) request.put ("wallet", wallet); request.put ("action", "wallet_key_valid"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string exists_text (response.json.get ("valid")); ASSERT_EQ ("1", exists_text); @@ -1037,11 +913,7 @@ TEST (rpc, wallet_create) boost::property_tree::ptree request; request.put ("action", "wallet_create"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string wallet_text (response.json.get ("wallet")); nano::wallet_id wallet_id; @@ -1069,11 +941,7 @@ TEST (rpc, wallet_create_seed) request.put ("action", "wallet_create"); request.put ("seed", seed.data.to_string ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); std::string wallet_text (response.json.get ("wallet")); nano::wallet_id wallet_id; @@ -1111,11 +979,7 @@ TEST (rpc, wallet_export) request.put ("action", "wallet_export"); request.put ("wallet", node->wallets.items.begin ()->first.to_string ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string wallet_json (response.json.get ("json")); bool error (false); @@ -1145,11 +1009,7 @@ TEST (rpc, wallet_destroy) request.put ("action", "wallet_destroy"); request.put ("wallet", wallet_id.to_string ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (node->wallets.items.end (), node->wallets.items.find (wallet_id)); } @@ -1183,11 +1043,7 @@ TEST (rpc, account_move) keys.push_back (std::make_pair ("", entry)); request.add_child ("accounts", keys); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ ("1", response.json.get ("moved")); ASSERT_TRUE (destination->exists (key.pub)); @@ -1212,11 +1068,7 @@ TEST (rpc, block) request.put ("action", "block"); request.put ("hash", node->latest (nano::genesis_account).to_string ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto contents (response.json.get ("contents")); ASSERT_FALSE (contents.empty ()); @@ -1240,11 +1092,7 @@ TEST (rpc, block_account) request.put ("action", "block_account"); request.put ("hash", genesis.hash ().to_string ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string account_text (response.json.get ("account")); nano::account account; @@ -1274,11 +1122,7 @@ TEST (rpc, chain) request.put ("block", block->hash ().to_string ()); request.put ("count", std::to_string (std::numeric_limits::max ())); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & blocks_node (response.json.get_child ("blocks")); std::vector blocks; @@ -1314,11 +1158,7 @@ TEST (rpc, chain_limit) request.put ("block", block->hash ().to_string ()); request.put ("count", 1); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & blocks_node (response.json.get_child ("blocks")); std::vector blocks; @@ -1354,11 +1194,7 @@ TEST (rpc, chain_offset) request.put ("count", std::to_string (std::numeric_limits::max ())); request.put ("offset", 1); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & blocks_node (response.json.get_child ("blocks")); std::vector blocks; @@ -1401,11 +1237,7 @@ TEST (rpc, frontier) request.put ("account", nano::account (0).to_account ()); request.put ("count", std::to_string (std::numeric_limits::max ())); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & frontiers_node (response.json.get_child ("frontiers")); std::unordered_map frontiers; @@ -1453,11 +1285,7 @@ TEST (rpc, frontier_limited) request.put ("account", nano::account (0).to_account ()); request.put ("count", std::to_string (100)); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & frontiers_node (response.json.get_child ("frontiers")); ASSERT_EQ (100, frontiers_node.size ()); @@ -1494,11 +1322,7 @@ TEST (rpc, frontier_startpoint) request.put ("account", source.begin ()->first.to_account ()); request.put ("count", std::to_string (1)); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & frontiers_node (response.json.get_child ("frontiers")); ASSERT_EQ (1, frontiers_node.size ()); @@ -1539,11 +1363,7 @@ TEST (rpc, history) request.put ("hash", uchange.hash ().to_string ()); request.put ("count", 100); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::vector> history_l; auto & history_node (response.json.get_child ("history")); @@ -1610,10 +1430,7 @@ TEST (rpc, account_history) request.put ("account", nano::genesis_account.to_account ()); request.put ("count", 100); test_response response (request, rpc.config.port, system.io_ctx); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); std::vector> history_l; auto & history_node (response.json.get_child ("history")); @@ -1657,10 +1474,7 @@ TEST (rpc, account_history) request.put ("reverse", true); request.put ("count", 1); test_response response (request, rpc.config.port, system.io_ctx); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); auto & history_node (response.json.get_child ("history")); ASSERT_EQ (1, history_node.size ()); @@ -1688,10 +1502,7 @@ TEST (rpc, account_history) request.add_child ("account_filter", filtered_accounts); request.put ("count", 100); test_response response (request, rpc.config.port, system.io_ctx); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); auto history_node (response.json.get_child ("history")); ASSERT_EQ (history_node.size (), 2); } @@ -1707,10 +1518,7 @@ TEST (rpc, account_history) request.add_child ("account_filter", filtered_accounts); request.put ("count", 100); test_response response (request, rpc.config.port, system.io_ctx); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); auto history_node (response.json.get_child ("history")); ASSERT_EQ (history_node.size (), 1); } @@ -1740,11 +1548,7 @@ TEST (rpc, history_count) request.put ("hash", receive->hash ().to_string ()); request.put ("count", 1); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & history_node (response.json.get_child ("history")); ASSERT_EQ (1, history_node.size ()); @@ -1772,28 +1576,16 @@ TEST (rpc, process_block) request.put ("block", json); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); - system.deadline_set (10s); - while (node1.latest (nano::test_genesis_key.pub) != send.hash ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1.latest (nano::test_genesis_key.pub) == send.hash ()); std::string send_hash (response.json.get ("hash")); ASSERT_EQ (send.hash ().to_string (), send_hash); } request.put ("json_block", true); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::error_code ec (nano::error_blocks::invalid_block); ASSERT_EQ (ec.message (), response.json.get ("error")); @@ -1822,11 +1614,7 @@ TEST (rpc, process_json_block) request.add_child ("block", block_node); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::error_code ec (nano::error_blocks::invalid_block); ASSERT_EQ (ec.message (), response.json.get ("error")); @@ -1834,17 +1622,9 @@ TEST (rpc, process_json_block) request.put ("json_block", true); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); - system.deadline_set (10s); - while (node1.latest (nano::test_genesis_key.pub) != send.hash ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1.latest (nano::test_genesis_key.pub) == send.hash ()); std::string send_hash (response.json.get ("hash")); ASSERT_EQ (send.hash ().to_string (), send_hash); } @@ -1877,17 +1657,9 @@ TEST (rpc, process_block_with_work_watcher) send->serialize_json (json); request.put ("block", json); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); - system.deadline_set (10s); - while (node1.latest (nano::test_genesis_key.pub) != send->hash ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node1.latest (nano::test_genesis_key.pub) == send->hash ()); system.deadline_set (10s); auto updated (false); double updated_multiplier; @@ -1925,11 +1697,7 @@ TEST (rpc, process_block_with_work_watcher) request.put ("block", json); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::error_code ec (nano::error_rpc::rpc_control_disabled); ASSERT_EQ (ec.message (), response.json.get ("error")); @@ -1939,11 +1707,7 @@ TEST (rpc, process_block_with_work_watcher) request.put ("watch_work", false); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::error_code ec (nano::error_rpc::rpc_control_disabled); ASSERT_NE (ec.message (), response.json.get ("error")); @@ -1973,11 +1737,7 @@ TEST (rpc, process_block_no_work) send.serialize_json (json); request.put ("block", json); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_FALSE (response.json.get ("error", "").empty ()); } @@ -2005,17 +1765,9 @@ TEST (rpc, process_republish) send.serialize_json (json); request.put ("block", json); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); - system.deadline_set (10s); - while (node2.latest (nano::test_genesis_key.pub) != send.hash ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node2.latest (nano::test_genesis_key.pub) == send.hash ()); } TEST (rpc, process_subtype_send) @@ -2041,35 +1793,21 @@ TEST (rpc, process_subtype_send) request.put ("block", json); request.put ("subtype", "receive"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::error_code ec (nano::error_rpc::invalid_subtype_balance); ASSERT_EQ (response.json.get ("error"), ec.message ()); request.put ("subtype", "change"); test_response response2 (request, rpc.config.port, system.io_ctx); - while (response2.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response2.status != 0); ASSERT_EQ (200, response2.status); ASSERT_EQ (response2.json.get ("error"), ec.message ()); request.put ("subtype", "send"); test_response response3 (request, rpc.config.port, system.io_ctx); - while (response3.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response3.status != 0); ASSERT_EQ (200, response3.status); ASSERT_EQ (send.hash ().to_string (), response3.json.get ("hash")); - system.deadline_set (10s); - while (system.nodes[1]->latest (nano::test_genesis_key.pub) != send.hash ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, system.nodes[1]->latest (nano::test_genesis_key.pub) == send.hash ()); } TEST (rpc, process_subtype_open) @@ -2099,35 +1837,21 @@ TEST (rpc, process_subtype_open) request.put ("block", json); request.put ("subtype", "send"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::error_code ec (nano::error_rpc::invalid_subtype_balance); ASSERT_EQ (response.json.get ("error"), ec.message ()); request.put ("subtype", "epoch"); test_response response2 (request, rpc.config.port, system.io_ctx); - while (response2.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response2.status != 0); ASSERT_EQ (200, response2.status); ASSERT_EQ (response2.json.get ("error"), ec.message ()); request.put ("subtype", "open"); test_response response3 (request, rpc.config.port, system.io_ctx); - while (response3.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response3.status != 0); ASSERT_EQ (200, response3.status); ASSERT_EQ (open.hash ().to_string (), response3.json.get ("hash")); - system.deadline_set (10s); - while (node2.latest (key.pub) != open.hash ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node2.latest (key.pub) == open.hash ()); } TEST (rpc, process_subtype_receive) @@ -2156,36 +1880,22 @@ TEST (rpc, process_subtype_receive) request.put ("block", json); request.put ("subtype", "send"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::error_code ec (nano::error_rpc::invalid_subtype_balance); ASSERT_EQ (response.json.get ("error"), ec.message ()); request.put ("subtype", "open"); test_response response2 (request, rpc.config.port, system.io_ctx); - while (response2.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response2.status != 0); ASSERT_EQ (200, response2.status); ec = nano::error_rpc::invalid_subtype_previous; ASSERT_EQ (response2.json.get ("error"), ec.message ()); request.put ("subtype", "receive"); test_response response3 (request, rpc.config.port, system.io_ctx); - while (response3.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response3.status != 0); ASSERT_EQ (200, response3.status); ASSERT_EQ (receive.hash ().to_string (), response3.json.get ("hash")); - system.deadline_set (10s); - while (node2.latest (nano::test_genesis_key.pub) != receive.hash ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node2.latest (nano::test_genesis_key.pub) == receive.hash ()); } TEST (rpc, process_ledger_insufficient_work) @@ -2214,11 +1924,7 @@ TEST (rpc, process_ledger_insufficient_work) request.put ("block", json); request.put ("subtype", "send"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::error_code ec (nano::error_process::insufficient_work); ASSERT_EQ (1, response.json.count ("error")); @@ -2317,11 +2023,7 @@ TEST (rpc, keepalive) ASSERT_EQ (nullptr, node0->network.udp_channels.channel (node1->network.endpoint ())); ASSERT_EQ (0, node0->network.size ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); system.deadline_set (10s); while (node0->network.find_channel (node1->network.endpoint ()) == nullptr) @@ -2351,11 +2053,7 @@ TEST (rpc, payment_init) request.put ("action", "payment_init"); request.put ("wallet", wallet_id.to_string ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ ("Ready", response.json.get ("status")); } @@ -2379,11 +2077,7 @@ TEST (rpc, payment_begin_end) request1.put ("action", "payment_begin"); request1.put ("wallet", wallet_id.to_string ()); test_response response1 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response1.status != 0); ASSERT_EQ (200, response1.status); auto account_text (response1.json.get ("account")); nano::account account; @@ -2414,11 +2108,7 @@ TEST (rpc, payment_begin_end) request2.put ("wallet", wallet_id.to_string ()); request2.put ("account", account.to_account ()); test_response response2 (request2, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response2.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response2.status != 0); ASSERT_EQ (200, response2.status); ASSERT_TRUE (wallet->exists (account)); ASSERT_NE (wallet->free_accounts.end (), wallet->free_accounts.find (account)); @@ -2447,11 +2137,7 @@ TEST (rpc, payment_end_nonempty) request1.put ("wallet", wallet_id.to_string ()); request1.put ("account", nano::test_genesis_key.pub.to_account ()); test_response response1 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response1.status != 0); ASSERT_EQ (200, response1.status); ASSERT_FALSE (response1.json.get ("error", "").empty ()); } @@ -2476,11 +2162,7 @@ TEST (rpc, payment_zero_balance) request1.put ("action", "payment_begin"); request1.put ("wallet", wallet_id.to_string ()); test_response response1 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response1.status != 0); ASSERT_EQ (200, response1.status); auto account_text (response1.json.get ("account")); nano::account account; @@ -2507,11 +2189,7 @@ TEST (rpc, payment_begin_reuse) request1.put ("action", "payment_begin"); request1.put ("wallet", wallet_id.to_string ()); test_response response1 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response1.status != 0); ASSERT_EQ (200, response1.status); auto account_text (response1.json.get ("account")); nano::account account; @@ -2523,20 +2201,13 @@ TEST (rpc, payment_begin_reuse) request2.put ("wallet", wallet_id.to_string ()); request2.put ("account", account.to_account ()); test_response response2 (request2, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response2.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response2.status != 0); ASSERT_EQ (200, response2.status); ASSERT_TRUE (wallet->exists (account)); ASSERT_NE (wallet->free_accounts.end (), wallet->free_accounts.find (account)); test_response response3 (request1, rpc.config.port, system.io_ctx); system.deadline_set (5s); - while (response3.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response3.status != 0); ASSERT_EQ (200, response3.status); auto account2_text (response1.json.get ("account")); nano::account account2; @@ -2568,11 +2239,7 @@ TEST (rpc, payment_begin_locked) request1.put ("action", "payment_begin"); request1.put ("wallet", wallet_id.to_string ()); test_response response1 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response1.status != 0); ASSERT_EQ (200, response1.status); ASSERT_FALSE (response1.json.get ("error", "").empty ()); } @@ -2598,11 +2265,7 @@ TEST (rpc, payment_wait) request1.put ("amount", nano::amount (nano::Mxrb_ratio).to_string_dec ()); request1.put ("timeout", "100"); test_response response1 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response1.status != 0); ASSERT_EQ (200, response1.status); ASSERT_EQ ("nothing", response1.json.get ("status")); request1.put ("timeout", "100000"); @@ -2615,19 +2278,13 @@ TEST (rpc, payment_wait) }); scoped_thread_name_io.renew (); test_response response2 (request1, rpc.config.port, system.io_ctx); - while (response2.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response2.status != 0); ASSERT_EQ (200, response2.status); ASSERT_EQ ("success", response2.json.get ("status")); request1.put ("amount", nano::amount (nano::Mxrb_ratio * 2).to_string_dec ()); test_response response3 (request1, rpc.config.port, system.io_ctx); system.deadline_set (5s); - while (response3.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response3.status != 0); ASSERT_EQ (200, response3.status); ASSERT_EQ ("success", response2.json.get ("status")); } @@ -2651,11 +2308,7 @@ TEST (rpc, peers) boost::property_tree::ptree request; request.put ("action", "peers"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & peers_node (response.json.get_child ("peers")); ASSERT_EQ (2, peers_node.size ()); @@ -2686,11 +2339,7 @@ TEST (rpc, peers_node_id) request.put ("action", "peers"); request.put ("peer_details", true); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & peers_node (response.json.get_child ("peers")); ASSERT_EQ (2, peers_node.size ()); @@ -2712,11 +2361,7 @@ TEST (rpc, pending) system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); auto block1 (system.wallet (0)->send_action (nano::test_genesis_key.pub, key1.pub, 100)); scoped_io_thread_name_change scoped_thread_name_io; - system.deadline_set (5s); - while (node->active.active (*block1)) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, !node->active.active (*block1)); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); nano::rpc_config rpc_config (nano::get_available_port (), true); @@ -2730,11 +2375,7 @@ TEST (rpc, pending) request.put ("count", "100"); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & blocks_node (response.json.get_child ("blocks")); ASSERT_EQ (1, blocks_node.size ()); @@ -2744,11 +2385,7 @@ TEST (rpc, pending) request.put ("sorting", "true"); // Sorting test { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & blocks_node (response.json.get_child ("blocks")); ASSERT_EQ (1, blocks_node.size ()); @@ -2760,11 +2397,7 @@ TEST (rpc, pending) request.put ("threshold", "100"); // Threshold test { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & blocks_node (response.json.get_child ("blocks")); ASSERT_EQ (1, blocks_node.size ()); @@ -2786,10 +2419,7 @@ TEST (rpc, pending) request.put ("threshold", "101"); { test_response response (request, rpc.config.port, system.io_ctx); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); auto & blocks_node (response.json.get_child ("blocks")); ASSERT_EQ (0, blocks_node.size ()); @@ -2799,11 +2429,7 @@ TEST (rpc, pending) request.put ("min_version", "true"); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & blocks_node (response.json.get_child ("blocks")); ASSERT_EQ (1, blocks_node.size ()); @@ -2827,11 +2453,7 @@ TEST (rpc, pending) auto check_block_response_count = [&system, &request, &rpc](size_t size) { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (size, response.json.get_child ("blocks").size ()); @@ -2853,11 +2475,7 @@ TEST (rpc, pending_burn) system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); auto block1 (system.wallet (0)->send_action (nano::test_genesis_key.pub, burn, 100)); scoped_io_thread_name_change scoped_thread_name_io; - system.deadline_set (5s); - while (node->active.active (*block1)) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, !node->active.active (*block1)); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); nano::rpc_config rpc_config (nano::get_available_port (), true); @@ -2871,11 +2489,7 @@ TEST (rpc, pending_burn) request.put ("count", "100"); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & blocks_node (response.json.get_child ("blocks")); ASSERT_EQ (1, blocks_node.size ()); @@ -2908,17 +2522,9 @@ TEST (rpc, search_pending) request.put ("action", "search_pending"); request.put ("wallet", wallet); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); - system.deadline_set (10s); - while (node->balance (nano::test_genesis_key.pub) != nano::genesis_amount) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->balance (nano::test_genesis_key.pub) == nano::genesis_amount); } TEST (rpc, version) @@ -2939,11 +2545,7 @@ TEST (rpc, version) boost::property_tree::ptree request1; request1.put ("action", "version"); test_response response1 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response1.status != 0); ASSERT_EQ (200, response1.status); ASSERT_EQ ("1", response1.json.get ("rpc_version")); ASSERT_EQ (200, response1.status); @@ -2995,11 +2597,7 @@ TEST (rpc, work_generate) request.put ("hash", hash.to_string ()); auto verify_response = [node, &rpc, &system](auto & request, auto & hash) { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (hash.to_string (), response.json.get ("hash")); auto work_text (response.json.get ("work")); @@ -3040,11 +2638,7 @@ TEST (rpc, work_generate_difficulty) uint64_t difficulty (0xfff0000000000000); request.put ("difficulty", nano::to_string_hex (difficulty)); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); auto work_text (response.json.get ("work")); uint64_t work; @@ -3063,11 +2657,7 @@ TEST (rpc, work_generate_difficulty) uint64_t difficulty (0xffff000000000000); request.put ("difficulty", nano::to_string_hex (difficulty)); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (20s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (20s, response.status != 0); ASSERT_EQ (200, response.status); auto work_text (response.json.get ("work")); uint64_t work; @@ -3079,11 +2669,7 @@ TEST (rpc, work_generate_difficulty) uint64_t difficulty (node->max_work_generate_difficulty (nano::work_version::work_1) + 1); request.put ("difficulty", nano::to_string_hex (difficulty)); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::error_code ec (nano::error_rpc::difficulty_limit); ASSERT_EQ (response.json.get ("error"), ec.message ()); @@ -3115,11 +2701,7 @@ TEST (rpc, work_generate_multiplier) double multiplier{ 100.0 }; request.put ("multiplier", multiplier); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); auto work_text (response.json.get_optional ("work")); ASSERT_TRUE (work_text.is_initialized ()); @@ -3136,11 +2718,7 @@ TEST (rpc, work_generate_multiplier) { request.put ("multiplier", -1.5); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::error_code ec (nano::error_rpc::bad_multiplier_format); ASSERT_EQ (response.json.get ("error"), ec.message ()); @@ -3149,11 +2727,7 @@ TEST (rpc, work_generate_multiplier) double max_multiplier (nano::difficulty::to_multiplier (node->max_work_generate_difficulty (nano::work_version::work_1), node->default_difficulty (nano::work_version::work_1))); request.put ("multiplier", max_multiplier + 1); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::error_code ec (nano::error_rpc::difficulty_limit); ASSERT_EQ (response.json.get ("error"), ec.message ()); @@ -3178,11 +2752,7 @@ TEST (rpc, work_generate_epoch_2) auto verify_response = [node, &rpc, &system](auto & request, nano::block_hash const & hash, uint64_t & out_difficulty) { request.put ("hash", hash.to_string ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto work_text (response.json.get ("work")); uint64_t work{ 0 }; @@ -3246,11 +2816,7 @@ TEST (rpc, work_generate_block_high) request.add_child ("block", json); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (1, response.json.count ("error")); ASSERT_EQ (std::error_code (nano::error_rpc::block_work_enough).message (), response.json.get ("error")); @@ -3285,11 +2851,7 @@ TEST (rpc, work_generate_block_low) request.put ("block", json); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); auto work_text (response.json.get_optional ("work")); ASSERT_TRUE (work_text.is_initialized ()); @@ -3329,11 +2891,7 @@ TEST (rpc, work_generate_block_root_mismatch) request.put ("block", json); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (1, response.json.count ("error")); ASSERT_EQ (std::error_code (nano::error_rpc::block_root_mismatch).message (), response.json.get ("error")); @@ -3376,11 +2934,7 @@ TEST (rpc, work_generate_block_ledger_epoch_2) while (!finished) { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); auto work_text (response.json.get_optional ("work")); ASSERT_TRUE (work_text.is_initialized ()); @@ -3425,10 +2979,7 @@ TEST (rpc, work_cancel) }); test_response response1 (request1, rpc.config.port, system.io_ctx); std::error_code ec; - while (response1.status == 0) - { - ec = system.poll (); - } + ASSERT_TIMELY (10s, response1.status != 0); ASSERT_EQ (200, response1.status); ASSERT_NO_ERROR (ec); } @@ -3457,11 +3008,7 @@ TEST (rpc, work_peer_bad) ASSERT_TRUE (work_a.is_initialized ()); work = *work_a; }); - system.deadline_set (5s); - while (nano::work_difficulty (nano::work_version::work_1, hash1, work) < nano::work_threshold_base (nano::work_version::work_1)) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, nano::work_difficulty (nano::work_version::work_1, hash1, work) >= nano::work_threshold_base (nano::work_version::work_1)); } TEST (rpc, work_peer_one) @@ -3487,11 +3034,7 @@ TEST (rpc, work_peer_one) ASSERT_TRUE (work_a.is_initialized ()); work = *work_a; }); - system.deadline_set (5s); - while (nano::work_difficulty (nano::work_version::work_1, key1.pub, work) < nano::work_threshold_base (nano::work_version::work_1)) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, nano::work_difficulty (nano::work_version::work_1, key1.pub, work) >= nano::work_threshold_base (nano::work_version::work_1)); } TEST (rpc, work_peer_many) @@ -3563,11 +3106,7 @@ TEST (rpc, work_version_invalid) request.put ("version", "work_invalid"); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (1, response.json.count ("error")); ASSERT_EQ (std::error_code (nano::error_rpc::bad_work_version).message (), response.json.get ("error")); @@ -3575,11 +3114,7 @@ TEST (rpc, work_version_invalid) request.put ("action", "work_validate"); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (1, response.json.count ("error")); ASSERT_EQ (std::error_code (nano::error_rpc::bad_work_version).message (), response.json.get ("error")); @@ -3603,11 +3138,7 @@ TEST (rpc, block_count) request1.put ("action", "block_count"); { test_response response1 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response1.status != 0); ASSERT_EQ (200, response1.status); ASSERT_EQ ("1", response1.json.get ("count")); ASSERT_EQ ("0", response1.json.get ("unchecked")); @@ -3630,11 +3161,7 @@ TEST (rpc, block_count) request1.put ("action", "block_count"); { test_response response1 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response1.status != 0); ASSERT_EQ (200, response1.status); ASSERT_EQ ("1", response1.json.get ("count")); ASSERT_EQ ("0", response1.json.get ("unchecked")); @@ -3658,11 +3185,7 @@ TEST (rpc, frontier_count) boost::property_tree::ptree request1; request1.put ("action", "frontier_count"); test_response response1 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response1.status != 0); ASSERT_EQ (200, response1.status); ASSERT_EQ ("1", response1.json.get ("count")); } @@ -3682,11 +3205,7 @@ TEST (rpc, account_count) boost::property_tree::ptree request1; request1.put ("action", "account_count"); test_response response1 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response1.status != 0); ASSERT_EQ (200, response1.status); ASSERT_EQ ("1", response1.json.get ("count")); } @@ -3706,11 +3225,7 @@ TEST (rpc, available_supply) boost::property_tree::ptree request1; request1.put ("action", "available_supply"); test_response response1 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response1.status != 0); ASSERT_EQ (200, response1.status); ASSERT_EQ ("0", response1.json.get ("available")); scoped_thread_name_io.reset (); @@ -3719,11 +3234,7 @@ TEST (rpc, available_supply) auto block (system.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, 1)); scoped_thread_name_io.renew (); test_response response2 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response2.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response2.status != 0); ASSERT_EQ (200, response2.status); ASSERT_EQ ("1", response2.json.get ("available")); scoped_thread_name_io.reset (); @@ -3731,10 +3242,7 @@ TEST (rpc, available_supply) scoped_thread_name_io.renew (); test_response response3 (request1, rpc.config.port, system.io_ctx); system.deadline_set (5s); - while (response3.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response3.status != 0); ASSERT_EQ (200, response3.status); ASSERT_EQ ("1", response3.json.get ("available")); } @@ -3755,11 +3263,7 @@ TEST (rpc, mrai_to_raw) request1.put ("action", "mrai_to_raw"); request1.put ("amount", "1"); test_response response1 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response1.status != 0); ASSERT_EQ (200, response1.status); ASSERT_EQ (nano::Mxrb_ratio.convert_to (), response1.json.get ("amount")); } @@ -3780,11 +3284,7 @@ TEST (rpc, mrai_from_raw) request1.put ("action", "mrai_from_raw"); request1.put ("amount", nano::Mxrb_ratio.convert_to ()); test_response response1 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response1.status != 0); ASSERT_EQ (200, response1.status); ASSERT_EQ ("1", response1.json.get ("amount")); } @@ -3805,11 +3305,7 @@ TEST (rpc, krai_to_raw) request1.put ("action", "krai_to_raw"); request1.put ("amount", "1"); test_response response1 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response1.status != 0); ASSERT_EQ (200, response1.status); ASSERT_EQ (nano::kxrb_ratio.convert_to (), response1.json.get ("amount")); } @@ -3830,11 +3326,7 @@ TEST (rpc, krai_from_raw) request1.put ("action", "krai_from_raw"); request1.put ("amount", nano::kxrb_ratio.convert_to ()); test_response response1 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response1.status != 0); ASSERT_EQ (200, response1.status); ASSERT_EQ ("1", response1.json.get ("amount")); } @@ -3855,11 +3347,7 @@ TEST (rpc, nano_to_raw) request1.put ("action", "nano_to_raw"); request1.put ("amount", "1"); test_response response1 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response1.status != 0); ASSERT_EQ (200, response1.status); ASSERT_EQ (nano::xrb_ratio.convert_to (), response1.json.get ("amount")); } @@ -3880,11 +3368,7 @@ TEST (rpc, nano_from_raw) request1.put ("action", "nano_from_raw"); request1.put ("amount", nano::xrb_ratio.convert_to ()); test_response response1 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response1.status != 0); ASSERT_EQ (200, response1.status); ASSERT_EQ ("1", response1.json.get ("amount")); } @@ -3905,11 +3389,7 @@ TEST (rpc, account_representative) request.put ("account", nano::genesis_account.to_account ()); request.put ("action", "account_representative"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string account_text1 (response.json.get ("representative")); ASSERT_EQ (account_text1, nano::genesis_account.to_account ()); @@ -3935,11 +3415,7 @@ TEST (rpc, account_representative_set) request.put ("wallet", node->wallets.items.begin ()->first.to_string ()); request.put ("action", "account_representative_set"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string block_text1 (response.json.get ("block")); nano::block_hash hash; @@ -3973,11 +3449,7 @@ TEST (rpc, account_representative_set_work_disabled) request.put ("action", "account_representative_set"); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (std::error_code (nano::error_common::disabled_work_generation).message (), response.json.get ("error")); } @@ -4019,11 +3491,7 @@ TEST (rpc, account_representative_set_epoch_2) request.put ("work", nano::to_string_hex (insufficient)); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::error_code ec (nano::error_common::invalid_work); ASSERT_EQ (1, response.json.count ("error")); @@ -4147,11 +3615,7 @@ TEST (rpc, wallet_seed) request.put ("action", "wallet_seed"); request.put ("wallet", node->wallets.items.begin ()->first.to_string ()); test_response response (request, rpc_config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); { std::string seed_text (response.json.get ("seed")); @@ -4262,11 +3726,7 @@ TEST (rpc, work_validate) request.put ("work", nano::to_string_hex (work1)); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (0, response.json.count ("valid")); ASSERT_TRUE (response.json.get ("valid_all")); @@ -4282,11 +3742,7 @@ TEST (rpc, work_validate) request.put ("work", nano::to_string_hex (work2)); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (0, response.json.count ("valid")); ASSERT_FALSE (response.json.get ("valid_all")); @@ -4304,11 +3760,7 @@ TEST (rpc, work_validate) request.put ("difficulty", nano::to_string_hex (result_difficulty)); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_TRUE (response.json.get ("valid")); ASSERT_TRUE (response.json.get ("valid_all")); @@ -4319,11 +3771,7 @@ TEST (rpc, work_validate) request.put ("difficulty", nano::to_string_hex (difficulty4)); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (result_difficulty >= difficulty4, response.json.get ("valid")); ASSERT_EQ (result_difficulty >= node1.default_difficulty (nano::work_version::work_1), response.json.get ("valid_all")); @@ -4333,11 +3781,7 @@ TEST (rpc, work_validate) request.put ("work", nano::to_string_hex (work3)); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_TRUE (response.json.get ("valid")); ASSERT_TRUE (response.json.get ("valid_all")); @@ -4367,11 +3811,7 @@ TEST (rpc, work_validate_epoch_2) request.put ("work", nano::to_string_hex (work)); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (0, response.json.count ("valid")); ASSERT_TRUE (response.json.get ("valid_all")); @@ -4388,11 +3828,7 @@ TEST (rpc, work_validate_epoch_2) scoped_thread_name_io.renew (); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (0, response.json.count ("valid")); ASSERT_FALSE (response.json.get ("valid_all")); @@ -4428,11 +3864,7 @@ TEST (rpc, successors) request.put ("block", genesis.to_string ()); request.put ("count", std::to_string (std::numeric_limits::max ())); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & blocks_node (response.json.get_child ("blocks")); std::vector blocks; @@ -4447,10 +3879,7 @@ TEST (rpc, successors) request.put ("action", "chain"); request.put ("reverse", "true"); test_response response2 (request, rpc.config.port, system.io_ctx); - while (response2.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response2.status != 0); ASSERT_EQ (200, response2.status); ASSERT_EQ (response.json, response2.json); } @@ -4509,17 +3938,9 @@ TEST (rpc, republish) request.put ("action", "republish"); request.put ("hash", send.hash ().to_string ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); - system.deadline_set (10s); - while (system.nodes[1]->balance (nano::test_genesis_key.pub) == nano::genesis_amount) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, system.nodes[1]->balance (nano::test_genesis_key.pub) != nano::genesis_amount); auto & blocks_node (response.json.get_child ("blocks")); std::vector blocks; for (auto i (blocks_node.begin ()), n (blocks_node.end ()); i != n; ++i) @@ -4533,11 +3954,7 @@ TEST (rpc, republish) request.put ("count", 1); test_response response1 (request, rpc.config.port, system.io_ctx); system.deadline_set (5s); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response1.status != 0); ASSERT_EQ (200, response1.status); blocks_node = response1.json.get_child ("blocks"); blocks.clear (); @@ -4551,10 +3968,7 @@ TEST (rpc, republish) request.put ("hash", open.hash ().to_string ()); request.put ("sources", 2); test_response response2 (request, rpc.config.port, system.io_ctx); - while (response2.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response2.status != 0); ASSERT_EQ (200, response2.status); blocks_node = response2.json.get_child ("blocks"); blocks.clear (); @@ -4632,11 +4046,7 @@ TEST (rpc, accounts_balances) peers_l.push_back (std::make_pair ("", entry)); request.add_child ("accounts", peers_l); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); for (auto & balances : response.json.get_child ("balances")) { @@ -4670,11 +4080,7 @@ TEST (rpc, accounts_frontiers) peers_l.push_back (std::make_pair ("", entry)); request.add_child ("accounts", peers_l); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); for (auto & frontiers : response.json.get_child ("frontiers")) { @@ -4693,11 +4099,7 @@ TEST (rpc, accounts_pending) system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv); auto block1 (system.wallet (0)->send_action (nano::test_genesis_key.pub, key1.pub, 100)); scoped_io_thread_name_change scoped_thread_name_io; - system.deadline_set (5s); - while (node->active.active (*block1)) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, !node->active.active (*block1)); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); nano::rpc_config rpc_config (nano::get_available_port (), true); @@ -4715,11 +4117,7 @@ TEST (rpc, accounts_pending) request.put ("count", "100"); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); for (auto & blocks : response.json.get_child ("blocks")) { @@ -4732,11 +4130,7 @@ TEST (rpc, accounts_pending) request.put ("sorting", "true"); // Sorting test { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); for (auto & blocks : response.json.get_child ("blocks")) { @@ -4751,11 +4145,7 @@ TEST (rpc, accounts_pending) request.put ("threshold", "100"); // Threshold test { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::unordered_map blocks; for (auto & pending : response.json.get_child ("blocks")) @@ -4778,11 +4168,7 @@ TEST (rpc, accounts_pending) request.put ("source", "true"); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::unordered_map amounts; std::unordered_map sources; @@ -4830,11 +4216,7 @@ TEST (rpc, blocks) peers_l.push_back (std::make_pair ("", entry)); request.add_child ("hashes", peers_l); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); for (auto & blocks : response.json.get_child ("blocks")) { @@ -4871,11 +4253,7 @@ TEST (rpc, wallet_info) request.put ("action", "wallet_info"); request.put ("wallet", node->wallets.items.begin ()->first.to_string ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string balance_text (response.json.get ("balance")); ASSERT_EQ ("340282366920938463463374607431768211454", balance_text); @@ -4954,11 +4332,7 @@ TEST (rpc, pending_exists) auto hash0 (node->latest (nano::genesis_account)); auto block1 (system.wallet (0)->send_action (nano::test_genesis_key.pub, key1.pub, 100)); scoped_io_thread_name_change scoped_thread_name_io; - system.deadline_set (5s); - while (node->active.active (*block1)) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, !node->active.active (*block1)); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); nano::rpc_config rpc_config (nano::get_available_port (), true); @@ -4970,11 +4344,7 @@ TEST (rpc, pending_exists) auto pending_exists = [&system, &request, &rpc](const char * exists_a) { test_response response0 (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response0.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response0.status != 0); ASSERT_EQ (200, response0.status); std::string exists_text (response0.json.get ("exists")); ASSERT_EQ (exists_a, exists_text); @@ -5132,11 +4502,7 @@ TEST (rpc, receive_minimum) boost::property_tree::ptree request; request.put ("action", "receive_minimum"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string amount (response.json.get ("amount")); ASSERT_EQ (node->config.receive_minimum.to_string_dec (), amount); @@ -5159,11 +4525,7 @@ TEST (rpc, receive_minimum_set) request.put ("amount", "100"); ASSERT_NE (node->config.receive_minimum.to_string_dec (), "100"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string success (response.json.get ("success")); ASSERT_TRUE (success.empty ()); @@ -5189,11 +4551,7 @@ TEST (rpc, work_get) request.put ("wallet", node->wallets.items.begin ()->first.to_string ()); request.put ("account", nano::test_genesis_key.pub.to_account ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string work_text (response.json.get ("work")); uint64_t work (1); @@ -5220,11 +4578,7 @@ TEST (rpc, wallet_work_get) request.put ("action", "wallet_work_get"); request.put ("wallet", node->wallets.items.begin ()->first.to_string ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto transaction (node->wallets.tx_begin_read ()); for (auto & works : response.json.get_child ("works")) @@ -5258,11 +4612,7 @@ TEST (rpc, work_set) request.put ("account", nano::test_genesis_key.pub.to_account ()); request.put ("work", nano::to_string_hex (work0)); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string success (response.json.get ("success")); ASSERT_TRUE (success.empty ()); @@ -5294,17 +4644,9 @@ TEST (rpc, search_pending_all) boost::property_tree::ptree request; request.put ("action", "search_pending_all"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); - system.deadline_set (10s); - while (node->balance (nano::test_genesis_key.pub) != nano::genesis_amount) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->balance (nano::test_genesis_key.pub) == nano::genesis_amount); } TEST (rpc, wallet_republish) @@ -5339,11 +4681,7 @@ TEST (rpc, wallet_republish) request.put ("wallet", node1.wallets.items.begin ()->first.to_string ()); request.put ("count", 1); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & blocks_node (response.json.get_child ("blocks")); std::vector blocks; @@ -5380,11 +4718,7 @@ TEST (rpc, delegators) request.put ("action", "delegators"); request.put ("account", nano::test_genesis_key.pub.to_account ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & delegators_node (response.json.get_child ("delegators")); boost::property_tree::ptree delegators; @@ -5421,11 +4755,7 @@ TEST (rpc, delegators_count) request.put ("action", "delegators_count"); request.put ("account", nano::test_genesis_key.pub.to_account ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string count (response.json.get ("count")); ASSERT_EQ ("2", count); @@ -5454,11 +4784,7 @@ TEST (rpc, account_info) // Test for a non existing account { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); auto error (response.json.get_optional ("error")); ASSERT_TRUE (error.is_initialized ()); @@ -5481,11 +4807,7 @@ TEST (rpc, account_info) request.put ("account", nano::test_genesis_key.pub.to_account ()); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string frontier (response.json.get ("frontier")); @@ -5519,11 +4841,7 @@ TEST (rpc, account_info) request.put ("representative", "1"); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); std::string weight2 (response.json.get ("weight")); ASSERT_EQ ("100", weight2); std::string pending2 (response.json.get ("pending")); @@ -5560,11 +4878,7 @@ TEST (rpc, json_block_input) send.serialize_json (json); request.add_child ("block", json); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); bool json_error{ false }; @@ -5600,11 +4914,7 @@ TEST (rpc, json_block_output) request.put ("json_block", "true"); request.put ("hash", send.hash ().to_string ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); // Make sure contents contains a valid JSON subtree instread of stringified json @@ -5654,11 +4964,7 @@ TEST (rpc, blocks_info) request.add_child ("hashes", hashes); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); check_blocks (response); } @@ -5669,22 +4975,14 @@ TEST (rpc, blocks_info) request.add_child ("hashes", hashes); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (std::error_code (nano::error_blocks::not_found).message (), response.json.get ("error")); } request.put ("include_not_found", "true"); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); check_blocks (response); auto & blocks_not_found (response.json.get_child ("blocks_not_found")); @@ -5695,11 +4993,7 @@ TEST (rpc, blocks_info) request.put ("pending", "1"); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); for (auto & blocks : response.json.get_child ("blocks")) { @@ -5744,11 +5038,7 @@ TEST (rpc, blocks_info_subtype) hashes.push_back (std::make_pair ("", entry)); request.add_child ("hashes", hashes); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); auto & blocks (response.json.get_child ("blocks")); ASSERT_EQ (3, blocks.size ()); auto send_subtype (blocks.get_child (send->hash ().to_string ()).get ("subtype")); @@ -5777,22 +5067,14 @@ TEST (rpc, work_peers_all) request.put ("address", "::1"); request.put ("port", "0"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string success (response.json.get ("success", "")); ASSERT_TRUE (success.empty ()); boost::property_tree::ptree request1; request1.put ("action", "work_peers"); test_response response1 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response1.status != 0); ASSERT_EQ (200, response1.status); auto & peers_node (response1.json.get_child ("work_peers")); std::vector peers; @@ -5805,20 +5087,13 @@ TEST (rpc, work_peers_all) boost::property_tree::ptree request2; request2.put ("action", "work_peers_clear"); test_response response2 (request2, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response2.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response2.status != 0); ASSERT_EQ (200, response2.status); success = response2.json.get ("success", ""); ASSERT_TRUE (success.empty ()); test_response response3 (request1, rpc.config.port, system.io_ctx); system.deadline_set (5s); - while (response3.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response3.status != 0); ASSERT_EQ (200, response3.status); peers_node = response3.json.get_child ("work_peers"); ASSERT_EQ (0, peers_node.size ()); @@ -5844,11 +5119,7 @@ TEST (rpc, block_count_type) boost::property_tree::ptree request; request.put ("action", "block_count_type"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string send_count (response.json.get ("send")); ASSERT_EQ ("0", send_count); @@ -5894,11 +5165,7 @@ TEST (rpc, ledger) request.put ("count", "1"); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); for (auto & account : response.json.get_child ("accounts")) { std::string account_text (account.first); @@ -5929,11 +5196,7 @@ TEST (rpc, ledger) request.put ("representative", true); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); for (auto & account : response.json.get_child ("accounts")) { boost::optional weight (account.second.get_optional ("weight")); @@ -5952,11 +5215,7 @@ TEST (rpc, ledger) request.put ("threshold", genesis_balance + 1); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); auto & accounts (response.json.get_child ("accounts")); ASSERT_EQ (1, accounts.size ()); auto account (accounts.begin ()); @@ -5976,11 +5235,7 @@ TEST (rpc, ledger) request.put ("pending", true); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); auto & accounts (response.json.get_child ("accounts")); ASSERT_EQ (1, accounts.size ()); auto account (accounts.begin ()); @@ -6009,11 +5264,7 @@ TEST (rpc, accounts_create) request.put ("wallet", node->wallets.items.begin ()->first.to_string ()); request.put ("count", "8"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & accounts (response.json.get_child ("accounts")); for (auto i (accounts.begin ()), n (accounts.end ()); i != n; ++i) @@ -6057,11 +5308,7 @@ TEST (rpc, block_create) request.put ("destination", key.pub.to_account ()); request.put ("work", nano::to_string_hex (send_work)); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string send_hash (response.json.get ("hash")); ASSERT_EQ (send.hash ().to_string (), send_hash); @@ -6086,11 +5333,7 @@ TEST (rpc, block_create) request1.put ("source", send.hash ().to_string ()); request1.put ("work", nano::to_string_hex (open_work)); test_response response1 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response1.status != 0); ASSERT_EQ (200, response1.status); std::string open_hash (response1.json.get ("hash")); ASSERT_EQ (open.hash ().to_string (), open_hash); @@ -6104,11 +5347,7 @@ TEST (rpc, block_create) scoped_thread_name_io.renew (); request1.put ("representative", key.pub.to_account ()); test_response response2 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response2.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response2.status != 0); ASSERT_EQ (200, response2.status); std::string open2_hash (response2.json.get ("hash")); ASSERT_NE (open.hash ().to_string (), open2_hash); // different blocks with wrong representative @@ -6117,11 +5356,7 @@ TEST (rpc, block_create) request1.put ("type", "change"); request1.put ("work", nano::to_string_hex (change_work)); test_response response4 (request1, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response4.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response4.status != 0); ASSERT_EQ (200, response4.status); std::string change_hash (response4.json.get ("hash")); ASSERT_EQ (change.hash ().to_string (), change_hash); @@ -6144,11 +5379,7 @@ TEST (rpc, block_create) request2.put ("previous", change.hash ().to_string ()); request2.put ("work", nano::to_string_hex (*node1.work_generate_blocking (change.hash ()))); test_response response5 (request2, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response5.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response5.status != 0); ASSERT_EQ (200, response5.status); std::string receive_hash (response4.json.get ("hash")); auto receive_text (response5.json.get ("block")); @@ -6187,11 +5418,7 @@ TEST (rpc, block_create_state) nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor); rpc.start (); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string state_hash (response.json.get ("hash")); auto state_text (response.json.get ("block")); @@ -6235,11 +5462,7 @@ TEST (rpc, block_create_state_open) nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor); rpc.start (); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string state_hash (response.json.get ("hash")); auto state_text (response.json.get ("block")); @@ -6294,11 +5517,7 @@ TEST (rpc, block_create_state_request_work) nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor); rpc.start (); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); boost::property_tree::ptree block_l; std::stringstream block_stream (response.json.get ("block")); @@ -6338,11 +5557,7 @@ TEST (rpc, block_create_open_epoch_v2) nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor); rpc.start (); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string state_hash (response.json.get ("hash")); auto state_text (response.json.get ("block")); @@ -6396,11 +5611,7 @@ TEST (rpc, block_create_receive_epoch_v2) nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor); rpc.start (); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string state_hash (response.json.get ("hash")); auto state_text (response.json.get ("block")); @@ -6452,11 +5663,7 @@ TEST (rpc, block_create_send_epoch_v2) nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor); rpc.start (); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string state_hash (response.json.get ("hash")); auto state_text (response.json.get ("block")); @@ -6498,11 +5705,7 @@ TEST (rpc, block_hash) send.serialize_json (json); request.put ("block", json); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string send_hash (response.json.get ("hash")); ASSERT_EQ (send.hash ().to_string (), send_hash); @@ -6530,11 +5733,7 @@ TEST (rpc, wallet_lock) request.put ("wallet", wallet); request.put ("action", "wallet_lock"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string account_text1 (response.json.get ("locked")); ASSERT_EQ (account_text1, "1"); @@ -6560,11 +5759,7 @@ TEST (rpc, wallet_locked) request.put ("wallet", wallet); request.put ("action", "wallet_locked"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string account_text1 (response.json.get ("locked")); ASSERT_EQ (account_text1, "0"); @@ -6590,11 +5785,7 @@ TEST (rpc, wallet_create_fail) boost::property_tree::ptree request; request.put ("action", "wallet_create"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (std::error_code (nano::error_common::wallet_lmdb_max_dbs).message (), response.json.get ("error")); } @@ -6625,11 +5816,7 @@ TEST (rpc, wallet_ledger) request.put ("sorting", "1"); request.put ("count", "1"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); for (auto & accounts : response.json.get_child ("accounts")) { std::string account_text (accounts.first); @@ -6658,11 +5845,7 @@ TEST (rpc, wallet_ledger) request.put ("pending", "1"); request.put ("representative", "false"); test_response response2 (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response2.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response2.status != 0); for (auto & accounts : response2.json.get_child ("accounts")) { boost::optional weight (accounts.second.get_optional ("weight")); @@ -6699,11 +5882,7 @@ TEST (rpc, wallet_add_watch) peers_l.push_back (std::make_pair ("", entry)); request.add_child ("accounts", peers_l); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string success (response.json.get ("success")); ASSERT_TRUE (success.empty ()); @@ -6717,11 +5896,7 @@ TEST (rpc, wallet_add_watch) request.add_child ("accounts", peers_l); test_response response_error (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response_error.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response_error.status != 0); ASSERT_EQ (200, response_error.status); std::error_code ec (nano::error_common::bad_public_key); ASSERT_EQ (response_error.json.get ("error"), ec.message ()); @@ -6738,11 +5913,7 @@ TEST (rpc, online_reps) auto send_block (system.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, nano::Gxrb_ratio)); ASSERT_NE (nullptr, send_block); scoped_io_thread_name_change scoped_thread_name_io; - system.deadline_set (10s); - while (node2->online_reps.list ().empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, !node2->online_reps.list ().empty ()); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*system.nodes[1], node_rpc_config); nano::rpc_config rpc_config (nano::get_available_port (), true); @@ -6753,11 +5924,7 @@ TEST (rpc, online_reps) boost::property_tree::ptree request; request.put ("action", "representatives_online"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto representatives (response.json.get_child ("representatives")); auto item (representatives.begin ()); @@ -6765,19 +5932,11 @@ TEST (rpc, online_reps) ASSERT_EQ (nano::test_genesis_key.pub.to_account (), item->second.get ("")); boost::optional weight (item->second.get_optional ("weight")); ASSERT_FALSE (weight.is_initialized ()); - system.deadline_set (5s); - while (node2->block (send_block->hash ()) == nullptr) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node2->block (send_block->hash ())); //Test weight option request.put ("weight", "true"); test_response response2 (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response2.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response2.status != 0); auto representatives2 (response2.json.get_child ("representatives")); auto item2 (representatives2.begin ()); ASSERT_NE (representatives2.end (), item2); @@ -6790,45 +5949,25 @@ TEST (rpc, online_reps) auto send (system.wallet (0)->send_action (nano::test_genesis_key.pub, new_rep, node1->config.receive_minimum.number ())); scoped_thread_name_io.renew (); ASSERT_NE (nullptr, send); - system.deadline_set (5s); - while (node2->block (send->hash ()) == nullptr) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node2->block (send->hash ())); scoped_thread_name_io.reset (); auto receive (system.wallet (1)->receive_action (*send, new_rep, node1->config.receive_minimum.number ())); scoped_thread_name_io.renew (); ASSERT_NE (nullptr, receive); - system.deadline_set (5s); - while (node2->block (receive->hash ()) == nullptr) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node2->block (receive->hash ())); scoped_thread_name_io.reset (); auto change (system.wallet (0)->change_action (nano::test_genesis_key.pub, new_rep)); scoped_thread_name_io.renew (); ASSERT_NE (nullptr, change); - system.deadline_set (5s); - while (node2->block (change->hash ()) == nullptr) - { - ASSERT_NO_ERROR (system.poll ()); - } - system.deadline_set (5s); - while (node2->online_reps.list ().size () != 2) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node2->block (change->hash ())); + ASSERT_TIMELY (5s, node2->online_reps.list ().size () != 2); boost::property_tree::ptree child_rep; child_rep.put ("", new_rep.to_account ()); boost::property_tree::ptree filtered_accounts; filtered_accounts.push_back (std::make_pair ("", child_rep)); request.add_child ("accounts", filtered_accounts); test_response response3 (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response3.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response3.status != 0); auto representatives3 (response3.json.get_child ("representatives")); auto item3 (representatives3.begin ()); ASSERT_NE (representatives3.end (), item3); @@ -6879,20 +6018,12 @@ TEST (rpc, confirmation_height_currently_processing) auto write_guard = node->write_database_queue.wait (nano::writer::testing); node->block_confirm (frontier); - system.deadline_set (10s); - while (node->confirmation_height_processor.current () != frontier->hash ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->confirmation_height_processor.current () == frontier->hash ()); // Make the request { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); auto hash (response.json.get ("hash")); ASSERT_EQ (frontier->hash ().to_string (), hash); @@ -6900,20 +6031,12 @@ TEST (rpc, confirmation_height_currently_processing) } // Wait until confirmation has been set and not processing anything - system.deadline_set (10s); - while (!node->confirmation_height_processor.current ().is_zero () || node->confirmation_height_processor.awaiting_processing_size () != 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->confirmation_height_processor.current ().is_zero () && node->confirmation_height_processor.awaiting_processing_size () == 0); // Make the same request, it should now return an error { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); std::error_code ec (nano::error_rpc::confirmation_height_not_processing); ASSERT_EQ (response.json.get ("error"), ec.message ()); @@ -6929,11 +6052,7 @@ TEST (rpc, confirmation_history) ASSERT_TRUE (node->active.list_recently_cemented ().empty ()); auto block (system.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, nano::Gxrb_ratio)); scoped_io_thread_name_change scoped_thread_name_io; - system.deadline_set (10s); - while (node->active.list_recently_cemented ().empty ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, !node->active.list_recently_cemented ().empty ()); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); nano::rpc_config rpc_config (nano::get_available_port (), true); @@ -6944,11 +6063,7 @@ TEST (rpc, confirmation_history) boost::property_tree::ptree request; request.put ("action", "confirmation_history"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto representatives (response.json.get_child ("confirmations")); auto item (representatives.begin ()); @@ -6978,11 +6093,7 @@ TEST (rpc, confirmation_history_hash) auto send2 (system.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, nano::Gxrb_ratio)); auto send3 (system.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, nano::Gxrb_ratio)); scoped_io_thread_name_change scoped_thread_name_io; - system.deadline_set (10s); - while (node->active.list_recently_cemented ().size () != 3) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->active.list_recently_cemented ().size () == 3); nano::node_rpc_config node_rpc_config; nano::ipc::ipc_server ipc_server (*node, node_rpc_config); nano::rpc_config rpc_config (nano::get_available_port (), true); @@ -6994,11 +6105,7 @@ TEST (rpc, confirmation_history_hash) request.put ("action", "confirmation_history"); request.put ("hash", send2->hash ().to_string ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto representatives (response.json.get_child ("confirmations")); ASSERT_EQ (representatives.size (), 1); @@ -7038,11 +6145,7 @@ TEST (rpc, block_confirm) request.put ("action", "block_confirm"); request.put ("hash", send1->hash ().to_string ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ ("1", response.json.get ("started")); } @@ -7064,11 +6167,7 @@ TEST (rpc, block_confirm_absent) request.put ("action", "block_confirm"); request.put ("hash", "0"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (std::error_code (nano::error_blocks::not_found).message (), response.json.get ("error")); } @@ -7102,11 +6201,7 @@ TEST (rpc, block_confirm_confirmed) request.put ("action", "block_confirm"); request.put ("hash", genesis.hash ().to_string ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ ("1", response.json.get ("started")); // Check confirmation history @@ -7114,11 +6209,7 @@ TEST (rpc, block_confirm_confirmed) ASSERT_EQ (1, confirmed.size ()); ASSERT_EQ (nano::genesis_hash, confirmed.begin ()->winner->hash ()); // Check callback - system.deadline_set (5s); - while (node->stats.count (nano::stat::type::error, nano::stat::detail::http_callback, nano::stat::dir::out) == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::error, nano::stat::detail::http_callback, nano::stat::dir::out) != 0); // Callback result is error because callback target port isn't listening ASSERT_EQ (1, node->stats.count (nano::stat::type::error, nano::stat::detail::http_callback, nano::stat::dir::out)); node->stop (); @@ -7139,11 +6230,7 @@ TEST (rpc, node_id) boost::property_tree::ptree request; request.put ("action", "node_id"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (node->node_id.prv.data.to_string (), response.json.get ("private")); ASSERT_EQ (node->node_id.pub.to_account (), response.json.get ("as_account")); @@ -7168,11 +6255,7 @@ TEST (rpc, stats_clear) boost::property_tree::ptree request; request.put ("action", "stats_clear"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); std::string success (response.json.get ("success")); ASSERT_TRUE (success.empty ()); ASSERT_EQ (0, node->stats.count (nano::stat::type::ledger, nano::stat::dir::in)); @@ -7201,11 +6284,7 @@ TEST (rpc, unchecked) request.put ("count", 2); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & blocks (response.json.get_child ("blocks")); ASSERT_EQ (2, blocks.size ()); @@ -7215,11 +6294,7 @@ TEST (rpc, unchecked) request.put ("json_block", true); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & blocks (response.json.get_child ("blocks")); ASSERT_EQ (2, blocks.size ()); @@ -7248,11 +6323,7 @@ TEST (rpc, unchecked_get) request.put ("hash", open->hash ().to_string ()); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (1, response.json.count ("contents")); auto timestamp (response.json.get ("modified_timestamp")); @@ -7261,11 +6332,7 @@ TEST (rpc, unchecked_get) request.put ("json_block", true); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & contents (response.json.get_child ("contents")); ASSERT_EQ ("state", contents.get ("type")); @@ -7297,24 +6364,10 @@ TEST (rpc, unchecked_clear) } request.put ("action", "unchecked_clear"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); - system.deadline_set (5s); - while (true) - { - auto transaction = node.store.tx_begin_read (); - if (node.store.unchecked_count (transaction) == 0) - { - break; - } - ASSERT_NO_ERROR (system.poll ()); - } - + ASSERT_TIMELY (10s, node.store.unchecked_count (node.store.tx_begin_read ()) == 0); ASSERT_EQ (node.ledger.cache.unchecked_count, 0); } @@ -7342,11 +6395,7 @@ TEST (rpc, unopened) boost::property_tree::ptree request; request.put ("action", "unopened"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & accounts (response.json.get_child ("accounts")); ASSERT_EQ (2, accounts.size ()); @@ -7359,11 +6408,7 @@ TEST (rpc, unopened) request.put ("action", "unopened"); request.put ("account", account2.to_account ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & accounts (response.json.get_child ("accounts")); ASSERT_EQ (1, accounts.size ()); @@ -7375,11 +6420,7 @@ TEST (rpc, unopened) request.put ("action", "unopened"); request.put ("account", nano::account (account2.number () + 1).to_account ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & accounts (response.json.get_child ("accounts")); ASSERT_EQ (0, accounts.size ()); @@ -7390,11 +6431,7 @@ TEST (rpc, unopened) request.put ("action", "unopened"); request.put ("count", "1"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & accounts (response.json.get_child ("accounts")); ASSERT_EQ (1, accounts.size ()); @@ -7406,11 +6443,7 @@ TEST (rpc, unopened) request.put ("action", "unopened"); request.put ("threshold", 5); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & accounts (response.json.get_child ("accounts")); ASSERT_EQ (1, accounts.size ()); @@ -7438,11 +6471,7 @@ TEST (rpc, unopened_burn) boost::property_tree::ptree request; request.put ("action", "unopened"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & accounts (response.json.get_child ("accounts")); ASSERT_EQ (0, accounts.size ()); @@ -7463,11 +6492,7 @@ TEST (rpc, unopened_no_accounts) boost::property_tree::ptree request; request.put ("action", "unopened"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & accounts (response.json.get_child ("accounts")); ASSERT_EQ (0, accounts.size ()); @@ -7489,11 +6514,7 @@ TEST (rpc, uptime) request.put ("action", "uptime"); std::this_thread::sleep_for (std::chrono::seconds (1)); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_LE (1, response.json.get ("seconds")); } @@ -7528,11 +6549,7 @@ TEST (rpc, wallet_history) request.put ("action", "wallet_history"); request.put ("wallet", node->wallets.items.begin ()->first.to_string ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::vector> history_l; auto & history_node (response.json.get_child ("history")); @@ -7586,21 +6603,14 @@ TEST (rpc, sign_hash) request.put ("hash", send.hash ().to_string ()); request.put ("key", key.prv.data.to_string ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); std::error_code ec (nano::error_rpc::sign_hash_disabled); ASSERT_EQ (response.json.get ("error"), ec.message ()); - node_rpc_config.enable_sign_hash = true; - test_response response2 (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response2.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + node_rpc_config.enable_sign_hash = true; + test_response response2 (request, rpc.config.port, system.io_ctx); + system.deadline_set (10s); + ASSERT_TIMELY (10s, response2.status != 0); ASSERT_EQ (200, response2.status); nano::signature signature; std::string signature_text (response2.json.get ("signature")); @@ -7633,11 +6643,7 @@ TEST (rpc, sign_block) send.serialize_json (json); request.put ("block", json); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); auto contents (response.json.get ("block")); boost::property_tree::ptree block_l; @@ -7673,11 +6679,7 @@ TEST (rpc, memory_stats) request.put ("action", "stats"); request.put ("type", "objects"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (response.json.get_child ("node").get_child ("vote_uniquer").get_child ("votes").get ("count"), "1"); @@ -7699,21 +6701,13 @@ TEST (rpc, block_confirmed) request.put ("action", "block_info"); request.put ("hash", "bad_hash1337"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (std::error_code (nano::error_blocks::invalid_block_hash).message (), response.json.get ("error")); request.put ("hash", "0"); test_response response1 (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response1.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response1.status != 0); ASSERT_EQ (200, response1.status); ASSERT_EQ (std::error_code (nano::error_blocks::not_found).message (), response1.json.get ("error")); @@ -7736,11 +6730,7 @@ TEST (rpc, block_confirmed) nano::block_hash latest (node->latest (nano::test_genesis_key.pub)); request.put ("hash", latest.to_string ()); test_response response2 (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response2.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response2.status != 0); ASSERT_EQ (200, response2.status); ASSERT_FALSE (response2.json.get ("confirmed")); @@ -7756,17 +6746,14 @@ TEST (rpc, block_confirmed) nano::lock_guard guard (node->active.mutex); election->confirm_once (); } - ASSERT_TIMELY (3s, node->block_confirmed (send->hash ())); + + // Wait until the confirmation height has been set + ASSERT_TIMELY (10s, node->ledger.block_confirmed (node->store.tx_begin_read (), send->hash ()) && !node->confirmation_height_processor.is_processing_block (send->hash ())); // Requesting confirmation for this should now succeed request.put ("hash", send->hash ().to_string ()); test_response response3 (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response3.status == 0) - { - ASSERT_FALSE (system.poll ()); - } - + ASSERT_TIMELY (5s, response3.status != 0); ASSERT_EQ (200, response3.status); ASSERT_TRUE (response3.json.get ("confirmed")); } @@ -7797,11 +6784,7 @@ TEST (rpc, database_txn_tracker) request.put ("action", "database_txn_tracker"); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::error_code ec (nano::error_common::tracking_not_enabled); ASSERT_EQ (response.json.get ("error"), ec.message ()); @@ -7825,11 +6808,7 @@ TEST (rpc, database_txn_tracker) boost::property_tree::ptree request; auto check_not_correct_amount = [&system, &request, &rpc_port = rpc.config.port]() { test_response response (request, rpc_port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::error_code ec (nano::error_common::invalid_amount); ASSERT_EQ (response.json.get ("error"), ec.message ()); @@ -7869,11 +6848,7 @@ TEST (rpc, database_txn_tracker) request.put ("min_read_time", "1000"); test_response response (request, rpc.config.port, system.io_ctx); // It can take a long time to generate stack traces - system.deadline_set (60s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (60s, response.status != 0); ASSERT_EQ (200, response.status); keep_txn_alive_promise.set_value (); std::vector>>> json_l; @@ -7930,11 +6905,7 @@ TEST (rpc, active_difficulty) auto expected_multiplier{ (1.5 + 4.2 + (trend_size - 2) * 1) / trend_size }; { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto network_minimum_text (response.json.get ("network_minimum")); uint64_t network_minimum; @@ -7952,11 +6923,7 @@ TEST (rpc, active_difficulty) request.put ("include_trend", true); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); auto trend_opt (response.json.get_child_optional ("difficulty_trend")); ASSERT_TRUE (trend_opt.is_initialized ()); auto & trend (trend_opt.get ()); @@ -8020,11 +6987,7 @@ TEST (rpc, simultaneous_calls) promise.get_future ().wait (); - system.deadline_set (60s); - while (std::any_of (test_responses.begin (), test_responses.end (), [](const auto & test_response) { return test_response->status == 0; })) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (60s, std::all_of (test_responses.begin (), test_responses.end (), [](const auto & test_response) { return test_response->status != 0; })); for (int i = 0; i < num; ++i) { @@ -8056,11 +7019,7 @@ TEST (rpc, in_process) request.put ("action", "account_balance"); request.put ("account", nano::test_genesis_key.pub.to_account ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); std::string balance_text (response.json.get ("balance")); ASSERT_EQ ("340282366920938463463374607431768211455", balance_text); @@ -8141,11 +7100,7 @@ TEST (rpc, deprecated_account_format) request.put ("action", "account_info"); request.put ("account", nano::test_genesis_key.pub.to_account ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); boost::optional deprecated_account_format (response.json.get_optional ("deprecated_account_format")); ASSERT_FALSE (deprecated_account_format.is_initialized ()); @@ -8153,11 +7108,7 @@ TEST (rpc, deprecated_account_format) account_text[4] = '-'; request.put ("account", account_text); test_response response2 (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response2.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response2.status != 0); ASSERT_EQ (200, response2.status); std::string frontier (response.json.get ("frontier")); ASSERT_EQ (nano::genesis_hash.to_string (), frontier); @@ -8204,29 +7155,14 @@ TEST (rpc, epoch_upgrade) request.put ("epoch", 1); request.put ("key", epoch_signer.prv.data.to_string ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ ("1", response.json.get ("started")); test_response response_fail (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response_fail.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response_fail.status != 0); ASSERT_EQ (200, response_fail.status); ASSERT_EQ ("0", response_fail.json.get ("started")); - system.deadline_set (5s); - bool done (false); - while (!done) - { - auto transaction (node->store.tx_begin_read ()); - done = (4 == node->store.account_count (transaction)); - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, 4 == node->store.account_count (node->store.tx_begin_read ())); // Check upgrade { auto transaction (node->store.tx_begin_read ()); @@ -8261,21 +7197,10 @@ TEST (rpc, epoch_upgrade) request.put ("epoch", 2); test_response response2 (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response2.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response2.status != 0); ASSERT_EQ (200, response2.status); ASSERT_EQ ("1", response2.json.get ("started")); - system.deadline_set (5s); - bool done2 (false); - while (!done2) - { - auto transaction (node->store.tx_begin_read ()); - done2 = (5 == node->store.account_count (transaction)); - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, 5 == node->store.account_count (node->store.tx_begin_read ())); // Check upgrade { auto transaction (node->store.tx_begin_read ()); @@ -8335,21 +7260,10 @@ TEST (rpc, epoch_upgrade_multithreaded) request.put ("epoch", 1); request.put ("key", epoch_signer.prv.data.to_string ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ ("1", response.json.get ("started")); - system.deadline_set (5s); - bool done (false); - while (!done) - { - auto transaction (node->store.tx_begin_read ()); - done = (4 == node->store.account_count (transaction)); - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, 4 == node->store.account_count (node->store.tx_begin_read ())); // Check upgrade { auto transaction (node->store.tx_begin_read ()); @@ -8384,21 +7298,10 @@ TEST (rpc, epoch_upgrade_multithreaded) request.put ("epoch", 2); test_response response2 (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response2.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response2.status != 0); ASSERT_EQ (200, response2.status); ASSERT_EQ ("1", response2.json.get ("started")); - system.deadline_set (5s); - bool done2 (false); - while (!done2) - { - auto transaction (node->store.tx_begin_read ()); - done2 = (5 == node->store.account_count (transaction)); - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, 5 == node->store.account_count (node->store.tx_begin_read ())); // Check upgrade { auto transaction (node->store.tx_begin_read ()); @@ -8446,21 +7349,13 @@ TEST (rpc, account_lazy_start) request.put ("action", "account_info"); request.put ("account", key.pub.to_account ()); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); boost::optional account_error (response.json.get_optional ("error")); ASSERT_TRUE (account_error.is_initialized ()); // Check processed blocks - system.deadline_set (10s); - while (node2->bootstrap_initiator.in_progress ()) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, !node2->bootstrap_initiator.in_progress ()); node2->block_processor.flush (); ASSERT_TRUE (node2->ledger.block_exists (send1->hash ())); ASSERT_TRUE (node2->ledger.block_exists (open->hash ())); @@ -8477,15 +7372,8 @@ TEST (rpc, receive) nano::keypair key1; wallet->insert_adhoc (key1.prv); auto send1 (wallet->send_action (nano::test_genesis_key.pub, key1.pub, node.config.receive_minimum.number (), *node.work_generate_blocking (nano::genesis_hash))); - system.deadline_set (5s); - while (node.balance (nano::test_genesis_key.pub) == nano::genesis_amount) - { - ASSERT_NO_ERROR (system.poll ()); - } - while (!node.store.account_exists (node.store.tx_begin_read (), key1.pub)) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node.balance (nano::test_genesis_key.pub) != nano::genesis_amount); + ASSERT_TIMELY (10s, !node.store.account_exists (node.store.tx_begin_read (), key1.pub)); // Send below minimum receive amount auto send2 (wallet->send_action (nano::test_genesis_key.pub, key1.pub, node.config.receive_minimum.number () - 1, *node.work_generate_blocking (send1->hash ()))); scoped_io_thread_name_change scoped_thread_name_io; @@ -8503,11 +7391,7 @@ TEST (rpc, receive) request.put ("block", send2->hash ().to_string ()); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto receive_text (response.json.get ("block")); nano::account_info info; @@ -8517,11 +7401,7 @@ TEST (rpc, receive) // Trying to receive the same block should fail with unreceivable { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (std::error_code (nano::error_process::unreceivable).message (), response.json.get ("error")); } @@ -8529,11 +7409,7 @@ TEST (rpc, receive) request.put ("block", nano::block_hash (send2->hash ().number () + 1).to_string ()); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (std::error_code (nano::error_blocks::not_found).message (), response.json.get ("error")); } @@ -8550,11 +7426,7 @@ TEST (rpc, receive_unopened) // Test receiving for unopened account nano::keypair key1; auto send1 (wallet->send_action (nano::test_genesis_key.pub, key1.pub, node.config.receive_minimum.number () - 1, *node.work_generate_blocking (nano::genesis_hash))); - system.deadline_set (5s); - while (node.balance (nano::test_genesis_key.pub) == nano::genesis_amount) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, !node.balance (nano::test_genesis_key.pub) != nano::genesis_amount); ASSERT_FALSE (node.store.account_exists (node.store.tx_begin_read (), key1.pub)); ASSERT_TRUE (node.store.block_exists (node.store.tx_begin_read (), send1->hash ())); wallet->insert_adhoc (key1.prv); // should not auto receive, amount sent was lower than minimum @@ -8573,11 +7445,7 @@ TEST (rpc, receive_unopened) request.put ("block", send1->hash ().to_string ()); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto receive_text (response.json.get ("block")); nano::account_info info; @@ -8592,11 +7460,7 @@ TEST (rpc, receive_unopened) nano::keypair key2; auto prev_amount (node.balance (nano::test_genesis_key.pub)); auto send2 (wallet->send_action (nano::test_genesis_key.pub, key2.pub, node.config.receive_minimum.number () - 1, *node.work_generate_blocking (send1->hash ()))); - system.deadline_set (5s); - while (node.balance (nano::test_genesis_key.pub) == prev_amount) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, !node.balance (nano::test_genesis_key.pub) != prev_amount); ASSERT_FALSE (node.store.account_exists (node.store.tx_begin_read (), key2.pub)); ASSERT_TRUE (node.store.block_exists (node.store.tx_begin_read (), send2->hash ())); nano::public_key rep; @@ -8607,11 +7471,7 @@ TEST (rpc, receive_unopened) request.put ("block", send2->hash ().to_string ()); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto receive_text (response.json.get ("block")); nano::account_info info; @@ -8639,11 +7499,7 @@ TEST (rpc, receive_work_disabled) ASSERT_TRUE (worker_node.work_generation_enabled ()); auto send1 (wallet->send_action (nano::test_genesis_key.pub, key1.pub, node.config.receive_minimum.number () - 1, *worker_node.work_generate_blocking (genesis.hash ()), false)); ASSERT_TRUE (send1 != nullptr); - system.deadline_set (5s); - while (node.balance (nano::test_genesis_key.pub) == nano::genesis_amount) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, node.balance (nano::test_genesis_key.pub) != nano::genesis_amount); ASSERT_FALSE (node.store.account_exists (node.store.tx_begin_read (), key1.pub)); ASSERT_TRUE (node.store.block_exists (node.store.tx_begin_read (), send1->hash ())); wallet->insert_adhoc (key1.prv); @@ -8662,11 +7518,7 @@ TEST (rpc, receive_work_disabled) request.put ("block", send1->hash ().to_string ()); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (std::error_code (nano::error_common::disabled_work_generation).message (), response.json.get ("error")); } @@ -8687,13 +7539,7 @@ TEST (rpc, telemetry_single) // Wait until peers are stored as they are done in the background auto peers_stored = false; - while (!peers_stored) - { - ASSERT_NO_ERROR (system.poll ()); - - auto transaction = system.nodes.back ()->store.tx_begin_read (); - peers_stored = system.nodes.back ()->store.peer_count (transaction) != 0; - } + ASSERT_TIMELY (10s, node1.store.peer_count (node1.store.tx_begin_read ()) != 0); // Missing port boost::property_tree::ptree request; @@ -8703,11 +7549,7 @@ TEST (rpc, telemetry_single) { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (std::error_code (nano::error_rpc::requires_port_and_address).message (), response.json.get ("error")); } @@ -8718,11 +7560,7 @@ TEST (rpc, telemetry_single) { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (std::error_code (nano::error_rpc::requires_port_and_address).message (), response.json.get ("error")); } @@ -8733,11 +7571,7 @@ TEST (rpc, telemetry_single) { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (std::error_code (nano::error_common::invalid_ip_address).message (), response.json.get ("error")); } @@ -8747,11 +7581,7 @@ TEST (rpc, telemetry_single) request.put ("port", "invalid port"); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (std::error_code (nano::error_common::invalid_port).message (), response.json.get ("error")); } @@ -8760,11 +7590,7 @@ TEST (rpc, telemetry_single) request.put ("port", node->network.endpoint ().port ()); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); nano::jsonconfig config (response.json); @@ -8789,14 +7615,7 @@ TEST (rpc, telemetry_all) rpc.start (); // Wait until peers are stored as they are done in the background - auto peers_stored = false; - while (!peers_stored) - { - ASSERT_NO_ERROR (system.poll ()); - - auto transaction = node1.store.tx_begin_read (); - peers_stored = node1.store.peer_count (transaction) != 0; - } + ASSERT_TIMELY (10s, node1.store.peer_count (node1.store.tx_begin_read ()) != 0); // First need to set up the cached data std::atomic done{ false }; @@ -8806,21 +7625,13 @@ TEST (rpc, telemetry_all) done = true; }); - system.deadline_set (10s); - while (!done) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, done); boost::property_tree::ptree request; request.put ("action", "telemetry"); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); nano::jsonconfig config (response.json); nano::telemetry_data telemetry_data; auto const should_ignore_identification_metrics = true; @@ -8832,11 +7643,7 @@ TEST (rpc, telemetry_all) request.put ("raw", "true"); test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); // This may fail if the response has taken longer than the cache cutoff time. @@ -8878,11 +7685,7 @@ TEST (rpc, telemetry_self) auto const should_ignore_identification_metrics = false; { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); nano::telemetry_data data; nano::jsonconfig config (response.json); @@ -8893,11 +7696,7 @@ TEST (rpc, telemetry_self) request.put ("address", "[::1]"); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); nano::telemetry_data data; nano::jsonconfig config (response.json); @@ -8908,11 +7707,7 @@ TEST (rpc, telemetry_self) request.put ("address", "127.0.0.1"); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); nano::telemetry_data data; nano::jsonconfig config (response.json); @@ -8924,11 +7719,7 @@ TEST (rpc, telemetry_self) request.put ("port", "0"); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (10s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (std::error_code (nano::error_rpc::peer_not_found).message (), response.json.get ("error")); } @@ -8970,11 +7761,7 @@ TEST (rpc, confirmation_active) request.put ("action", "confirmation_active"); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); auto & confirmations (response.json.get_child ("confirmations")); ASSERT_EQ (1, confirmations.size ()); @@ -9010,11 +7797,7 @@ TEST (rpc, confirmation_info) request.put ("json_block", "true"); { test_response response (request, rpc.config.port, system.io_ctx); - system.deadline_set (5s); - while (response.status == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (5s, response.status != 0); ASSERT_EQ (200, response.status); ASSERT_EQ (1, response.json.count ("announcements")); ASSERT_EQ (1, response.json.get ("voters")); diff --git a/nano/slow_test/node.cpp b/nano/slow_test/node.cpp index f09e092237..6f12d13cbf 100644 --- a/nano/slow_test/node.cpp +++ b/nano/slow_test/node.cpp @@ -78,10 +78,7 @@ TEST (system, receive_while_synchronizing) std::string block_text; block->serialize_json (block_text); })); - while (node1->balance (key.pub).is_zero ()) - { - system.poll (); - } + ASSERT_TIMELY (10s, !node1->balance (key.pub).is_zero ()); node1->stop (); system.stop (); runner.join (); @@ -150,11 +147,7 @@ TEST (wallet, multithreaded_send_async) } })); } - system.deadline_set (1000s); - while (system.nodes[0]->balance (nano::test_genesis_key.pub) != (nano::genesis_amount - 20 * 1000 * 1000)) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (1000s, system.nodes[0]->balance (nano::test_genesis_key.pub) == (nano::genesis_amount - 20 * 1000 * 1000)); } for (auto i (threads.begin ()), n (threads.end ()); i != n; ++i) { @@ -239,7 +232,7 @@ TEST (node, fork_storm) } } }); - system.poll (); + ASSERT_NO_ERROR (system.poll ()); if ((iteration & 0xff) == 0) { std::cerr << "Empty: " << empty << " single: " << single << std::endl; @@ -502,15 +495,10 @@ TEST (confirmation_height, many_accounts_single_confirmation) election_insertion_result.election->confirm_once (); } - system.deadline_set (120s); - auto transaction = node->store.tx_begin_read (); - while (!node->ledger.block_confirmed (transaction, last_open_hash)) - { - ASSERT_NO_ERROR (system.poll ()); - transaction.refresh (); - } + ASSERT_TIMELY (120s, node->ledger.block_confirmed (node->store.tx_begin_read (), last_open_hash)); // All frontiers (except last) should have 2 blocks and both should be confirmed + auto transaction = node->store.tx_begin_read (); for (auto i (node->store.latest_begin (transaction)), n (node->store.latest_end ()); i != n; ++i) { auto & account = i->first; @@ -533,16 +521,8 @@ TEST (confirmation_height, many_accounts_single_confirmation) ASSERT_EQ (node->ledger.stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed_bounded, nano::stat::dir::in), num_accounts * 2 - 2); ASSERT_EQ (node->ledger.stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed_unbounded, nano::stat::dir::in), 0); - system.deadline_set (40s); - while ((node->ledger.cache.cemented_count - 1) != node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::all, nano::stat::dir::out)) - { - ASSERT_NO_ERROR (system.poll ()); - } - system.deadline_set (10s); - while (node->active.election_winner_details_size () > 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (40s, (node->ledger.cache.cemented_count - 1) == node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::all, nano::stat::dir::out)); + ASSERT_TIMELY (10s, node->active.election_winner_details_size () == 0); } TEST (confirmation_height, many_accounts_many_confirmations) @@ -584,22 +564,14 @@ TEST (confirmation_height, many_accounts_many_confirmations) election_insertion_result.election->confirm_once (); } - system.deadline_set (1500s); auto const num_blocks_to_confirm = (num_accounts - 1) * 2; - while (node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in) != num_blocks_to_confirm) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (1500s, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in) == num_blocks_to_confirm); auto num_confirmed_bounded = node->ledger.stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed_bounded, nano::stat::dir::in); ASSERT_GE (num_confirmed_bounded, nano::confirmation_height::unbounded_cutoff); ASSERT_EQ (node->ledger.stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed_unbounded, nano::stat::dir::in), num_blocks_to_confirm - num_confirmed_bounded); - system.deadline_set (60s); - while ((node->ledger.cache.cemented_count - 1) != node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::all, nano::stat::dir::out)) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (60s, (node->ledger.cache.cemented_count - 1) == node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::all, nano::stat::dir::out)); auto transaction = node->store.tx_begin_read (); auto cemented_count = 0; @@ -611,17 +583,9 @@ TEST (confirmation_height, many_accounts_many_confirmations) ASSERT_EQ (num_blocks_to_confirm + 1, cemented_count); ASSERT_EQ (cemented_count, node->ledger.cache.cemented_count); - system.deadline_set (20s); - while ((node->ledger.cache.cemented_count - 1) != node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::all, nano::stat::dir::out)) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (20s, (node->ledger.cache.cemented_count - 1) == node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::all, nano::stat::dir::out)); - system.deadline_set (10s); - while (node->active.election_winner_details_size () > 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->active.election_winner_details_size () == 0); } TEST (confirmation_height, long_chains) @@ -688,17 +652,7 @@ TEST (confirmation_height, long_chains) election_insertion_result.election->confirm_once (); } - system.deadline_set (30s); - while (true) - { - auto transaction = node->store.tx_begin_read (); - if (node->ledger.block_confirmed (transaction, receive1->hash ())) - { - break; - } - - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (30s, node->ledger.block_confirmed (node->store.tx_begin_read (), receive1->hash ())); auto transaction (node->store.tx_begin_read ()); nano::account_info account_info; @@ -724,16 +678,8 @@ TEST (confirmation_height, long_chains) ASSERT_EQ (node->ledger.stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed_bounded, nano::stat::dir::in), num_blocks * 2 + 2); ASSERT_EQ (node->ledger.stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed_unbounded, nano::stat::dir::in), 0); - system.deadline_set (40s); - while ((node->ledger.cache.cemented_count - 1) != node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::all, nano::stat::dir::out)) - { - ASSERT_NO_ERROR (system.poll ()); - } - system.deadline_set (10s); - while (node->active.election_winner_details_size () > 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (40s, (node->ledger.cache.cemented_count - 1) == node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::all, nano::stat::dir::out)); + ASSERT_TIMELY (10s, node->active.election_winner_details_size () == 0); } TEST (confirmation_height, dynamic_algorithm) @@ -763,28 +709,16 @@ TEST (confirmation_height, dynamic_algorithm) } node->confirmation_height_processor.add (state_blocks.front ()->hash ()); - system.deadline_set (20s); - while (node->ledger.cache.cemented_count != 2) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (20s, node->ledger.cache.cemented_count == 2); node->confirmation_height_processor.add (latest_genesis); - system.deadline_set (20s); - while (node->ledger.cache.cemented_count != num_blocks + 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (20s, node->ledger.cache.cemented_count == num_blocks + 1); ASSERT_EQ (node->ledger.stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in), num_blocks); ASSERT_EQ (node->ledger.stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed_bounded, nano::stat::dir::in), 1); ASSERT_EQ (node->ledger.stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed_unbounded, nano::stat::dir::in), num_blocks - 1); - system.deadline_set (10s); - while (node->active.election_winner_details_size () > 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->active.election_winner_details_size () == 0); } /* @@ -845,10 +779,7 @@ TEST (confirmation_height, dynamic_algorithm_no_transition_while_pending) node->confirmation_height_processor.pause (); timer.restart (); - while (node->confirmation_height_processor.unbounded_processor.pending_writes_size == 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->confirmation_height_processor.unbounded_processor.pending_writes_size != 0); { // Make it so that the number of blocks exceed the unbounded cutoff would go into the bounded processor (but shouldn't due to unbounded pending writes) @@ -861,20 +792,12 @@ TEST (confirmation_height, dynamic_algorithm_no_transition_while_pending) node->confirmation_height_processor.unpause (); } - system.deadline_set (10s); - while (node->ledger.cache.cemented_count != num_blocks + 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->ledger.cache.cemented_count == num_blocks + 1); ASSERT_EQ (node->ledger.stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in), num_blocks); ASSERT_EQ (node->ledger.stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed_bounded, nano::stat::dir::in), 0); ASSERT_EQ (node->ledger.stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed_unbounded, nano::stat::dir::in), num_blocks); - system.deadline_set (10s); - while (node->active.election_winner_details_size () > 0) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, node->active.election_winner_details_size () == 0); } } @@ -1239,18 +1162,11 @@ TEST (telemetry, ongoing_requests) ASSERT_EQ (0, node_client->stats.count (nano::stat::type::bootstrap, nano::stat::detail::telemetry_ack, nano::stat::dir::in)); ASSERT_EQ (0, node_client->stats.count (nano::stat::type::bootstrap, nano::stat::detail::telemetry_req, nano::stat::dir::out)); - system.deadline_set (20s); - while (node_client->stats.count (nano::stat::type::message, nano::stat::detail::telemetry_ack, nano::stat::dir::in) != 1 || node_server->stats.count (nano::stat::type::message, nano::stat::detail::telemetry_ack, nano::stat::dir::in) != 1) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (20s, node_client->stats.count (nano::stat::type::message, nano::stat::detail::telemetry_ack, nano::stat::dir::in) == 1 && node_server->stats.count (nano::stat::type::message, nano::stat::detail::telemetry_ack, nano::stat::dir::in) == 1); // Wait till the next ongoing will be called, and add a 1s buffer for the actual processing auto time = std::chrono::steady_clock::now (); - while (std::chrono::steady_clock::now () < (time + node_client->telemetry->cache_plus_buffer_cutoff_time () + 1s)) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, std::chrono::steady_clock::now () >= (time + node_client->telemetry->cache_plus_buffer_cutoff_time () + 1s)); ASSERT_EQ (2, node_client->stats.count (nano::stat::type::message, nano::stat::detail::telemetry_ack, nano::stat::dir::in)); ASSERT_EQ (2, node_client->stats.count (nano::stat::type::message, nano::stat::detail::telemetry_req, nano::stat::dir::in)); @@ -1318,11 +1234,7 @@ namespace transport }); } - system.deadline_set (30s); - while (!shared_data.done) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (30s, shared_data.done); ASSERT_TRUE (std::all_of (node_data.begin (), node_data.end (), [](auto const & data) { return !data.keep_requesting_metrics; })); @@ -1406,11 +1318,7 @@ TEST (telemetry, all_peers_use_single_request_cache) done = true; }); - system.deadline_set (10s); - while (!done) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, done); } auto responses = node_client->telemetry->get_metrics (); @@ -1438,11 +1346,7 @@ TEST (telemetry, all_peers_use_single_request_cache) done = true; }); - system.deadline_set (10s); - while (!done) - { - ASSERT_NO_ERROR (system.poll ()); - } + ASSERT_TIMELY (10s, done); } responses = node_client->telemetry->get_metrics ();