From 539ca47fe2d1316f81133fee96bfb9cce3ae4059 Mon Sep 17 00:00:00 2001 From: Francisco Date: Tue, 1 Jun 2021 19:45:28 +0100 Subject: [PATCH] lib,bugfix: fix blocking queue unit test. Dtor cannot destroy object while a thread is still pushing data --- lib/test/adt/circular_buffer_test.cc | 29 ++++++++++++---------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/lib/test/adt/circular_buffer_test.cc b/lib/test/adt/circular_buffer_test.cc index a1f78a8b1..efd5c561e 100644 --- a/lib/test/adt/circular_buffer_test.cc +++ b/lib/test/adt/circular_buffer_test.cc @@ -207,7 +207,7 @@ void test_dyn_circular_buffer() TESTASSERT(C::count == 0); } -int test_queue_block_api() +void test_queue_block_api() { dyn_blocking_queue queue(100); @@ -229,31 +229,26 @@ int test_queue_block_api() queue.stop(); t.join(); - return SRSRAN_SUCCESS; } -int test_queue_block_api_2() +void test_queue_block_api_2() { std::thread t; - { - dyn_blocking_queue queue(100); - - t = std::thread([&queue]() { - int count = 0; - while (queue.push_blocking(count++)) { - } - }); + dyn_blocking_queue queue(100); - for (int i = 0; i < 10000; ++i) { - TESTASSERT(queue.pop_blocking() == i); + t = std::thread([&queue]() { + int count = 0; + while (queue.push_blocking(count++)) { } + }); - // queue dtor called + for (int i = 0; i < 10000; ++i) { + TESTASSERT(queue.pop_blocking() == i); } + queue.stop(); t.join(); - return SRSRAN_SUCCESS; } } // namespace srsran @@ -267,8 +262,8 @@ int main(int argc, char** argv) TESTASSERT(srsran::test_static_circular_buffer() == SRSRAN_SUCCESS); srsran::test_dyn_circular_buffer(); - TESTASSERT(srsran::test_queue_block_api() == SRSRAN_SUCCESS); - TESTASSERT(srsran::test_queue_block_api_2() == SRSRAN_SUCCESS); + srsran::test_queue_block_api(); + srsran::test_queue_block_api_2(); srsran::console("Success\n"); return SRSRAN_SUCCESS; } \ No newline at end of file