Skip to content

Commit

Permalink
Fix unstable unittest ThreadedWorker.ErrorInWorkerWithNonEmptyQueue (
Browse files Browse the repository at this point in the history
  • Loading branch information
JaySon-Huang authored Jun 15, 2023
1 parent d15d97d commit 338db64
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions dbms/src/Common/tests/gtest_threaded_worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,21 @@ TEST(ThreadedWorker, ErrorInWorkerWithNonEmptyQueue)
result = w.result_queue->pop(r);
ASSERT_EQ(result, MPMCQueueResult::OK);

result = w.result_queue->pop(r);
ASSERT_EQ(result, MPMCQueueResult::CANCELLED);
// Because the concurrency is 2, there could be a chance that some new result
// is pushed into the result_queue before exception cancel all the wokers.
// As long as the queue is cancelled before all elements are handled, consider
// this test passed.
bool error_happened = false;
for (size_t i = 0; i < 3; ++i)
{
result = w.result_queue->pop(r);
if (result == MPMCQueueResult::CANCELLED)
{
error_happened = true;
break;
}
}
ASSERT_TRUE(error_happened);

result = w.source_queue->push(10);
ASSERT_EQ(result, MPMCQueueResult::CANCELLED);
Expand Down

0 comments on commit 338db64

Please sign in to comment.