]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1136] fixed unittests
authorRazvan Becheriu <razvan@isc.org>
Sun, 8 Mar 2020 15:37:38 +0000 (17:37 +0200)
committerRazvan Becheriu <razvan@isc.org>
Fri, 20 Mar 2020 11:50:40 +0000 (13:50 +0200)
src/lib/util/tests/thread_pool_unittest.cc

index dde1c9999e25d66ec733bc9565d1b84bcca9fb91..5736480c1aec543b8c9dff111056f4606e242220 100644 (file)
@@ -29,12 +29,6 @@ public:
     ThreadPoolTest() : thread_count_(0), count_(0), wait_(false) {
     }
 
-    /// @brief task function
-    void runTryStopAndWait(ThreadPool<CallBack> &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<CallBack>* 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));