From 01139be40ccd031cb5cf7c9793c1983b377b2805 Mon Sep 17 00:00:00 2001 From: Yaming Kuang Date: Wed, 27 Sep 2023 16:43:14 -0700 Subject: [PATCH] fix test case race --- src/tests/test_blk_read_tracker.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/tests/test_blk_read_tracker.cpp b/src/tests/test_blk_read_tracker.cpp index 30b5a7861..d8a482764 100644 --- a/src/tests/test_blk_read_tracker.cpp +++ b/src/tests/test_blk_read_tracker.cpp @@ -364,6 +364,16 @@ TEST_F(BlkReadTrackerTest, TestThreadedInsertAndRemove) { LOGINFO("Step 2: threaded insert issued."); + for (auto& t : op_threads) { + t.join(); + } + + // remove has to wait for insert to complete because if insert thread runs slower than remove, it might assert + // complaining no elements are found in map; + + LOGINFO("Step 3: threaded insert joined."); + op_threads.clear(); + for (auto i = 0ul; i < bids.size(); ++i) { for (auto j = 0ul; j < repeat; ++j) { std::thread t([this, &bids, i]() { get_inst()->remove(bids[i]); }); @@ -371,7 +381,7 @@ TEST_F(BlkReadTrackerTest, TestThreadedInsertAndRemove) { } } - LOGINFO("Step 3: threaded remove issued."); + LOGINFO("Step 4: threaded remove issued."); for (auto& t : op_threads) { t.join(); } @@ -412,6 +422,13 @@ TEST_F(BlkReadTrackerTest, TestThreadedInsertWaitonThenRemove) { op_threads.push_back(std::move(t)); } + // wait for all insert to complete, otherwise it will race with remove thread; + for (auto& t : op_threads) { + t.join(); + } + + op_threads.clear(); + LOGINFO("Step 3: threaded wait_on issued on all bids."); for (auto i = 0ul; i < bids.size(); ++i) {