From: Razvan Becheriu Date: Sun, 8 Mar 2020 15:37:38 +0000 (+0200) Subject: [#1136] fixed unittests X-Git-Tag: Kea-1.7.6~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a71ec0f84919a99bd91ef63b6c4b3a10a5d94ee;p=thirdparty%2Fkea.git [#1136] fixed unittests --- diff --git a/src/lib/util/tests/thread_pool_unittest.cc b/src/lib/util/tests/thread_pool_unittest.cc index dde1c9999e..5736480c1a 100644 --- a/src/lib/util/tests/thread_pool_unittest.cc +++ b/src/lib/util/tests/thread_pool_unittest.cc @@ -29,12 +29,6 @@ public: ThreadPoolTest() : thread_count_(0), count_(0), wait_(false) { } - /// @brief task function - void runTryStopAndWait(ThreadPool &thread_pool) { - EXPECT_THROW(thread_pool.stop(), InvalidOperation); - EXPECT_NO_THROW(runAndWait()); - } - /// @brief task function which registers the thread id and signals main /// thread to stop waiting and then waits for main thread to signal to exit void runAndWait() { @@ -63,6 +57,13 @@ public: cv_.notify_all(); } + /// @brief task function which tries to stop the thread pool and then calls + /// @ref runAndWait + void runTryStopAndWait(ThreadPool* thread_pool) { + EXPECT_THROW(thread_pool->stop(), InvalidOperation); + EXPECT_NO_THROW(runAndWait()); + } + /// @brief reset all counters and internal test state void reset(uint32_t thread_count) { // stop test threads @@ -393,10 +394,15 @@ TEST_F(ThreadPoolTest, testStartAndStop) { // the thread count should be 0 ASSERT_EQ(thread_pool.size(), 0); + items_count = 16; + thread_count = 16; + // prepare setup + reset(thread_count); + // create tasks which try to stop the thread pool and then block thread pool // threads until signaled by main thread to force all threads of the thread // pool to run exactly one task - call_back = std::bind(&ThreadPoolTest::runTryStopAndWait, this, thread_pool); + call_back = std::bind(&ThreadPoolTest::runTryStopAndWait, this, &thread_pool); // calling start should create the threads and should keep the queued items EXPECT_NO_THROW(thread_pool.start(thread_count));