From c1e94c0148251476773d5d0bbf6b839d3443efbb Mon Sep 17 00:00:00 2001 From: clemahieu Date: Tue, 25 Feb 2020 09:18:32 +0000 Subject: [PATCH] Reworking confirmation_height.dependent_election test so it's less prone to race conditions. (#2589) --- nano/core_test/confirmation_height.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/nano/core_test/confirmation_height.cpp b/nano/core_test/confirmation_height.cpp index 426debef..5f93aa8e 100644 --- a/nano/core_test/confirmation_height.cpp +++ b/nano/core_test/confirmation_height.cpp @@ -1171,9 +1171,6 @@ TEST (confirmation_height, dependent_election) add_callback_stats (*node); - // Prevent the confirmation height processor from doing any processing - node->confirmation_height_processor.pause (); - // Wait until it has been processed node->block_confirm (send2); system.deadline_set (10s); @@ -1182,20 +1179,17 @@ TEST (confirmation_height, dependent_election) ASSERT_NO_ERROR (system.poll ()); } - system.deadline_set (10s); - while (node->confirmation_height_processor.awaiting_processing_size () != 1) { - ASSERT_NO_ERROR (system.poll ()); + // The write guard prevents the confirmation height processor doing any writes. + system.deadline_set (10s); + auto write_guard = node->write_database_queue.wait (nano::writer::testing); + while (!node->write_database_queue.contains (nano::writer::confirmation_height)) + { + ASSERT_NO_ERROR (system.poll ()); + } } - { - nano::lock_guard guard (node->confirmation_height_processor.mutex); - ASSERT_EQ (*node->confirmation_height_processor.awaiting_processing.begin (), send2->hash ()); - } - - // Now put the other block in active so it can be confirmed as a dependent election node->block_confirm (send1); - node->confirmation_height_processor.unpause (); system.deadline_set (10s); while (node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) != 3)