Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/test/worker_pool_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/test/worker_pool_test.cpp')
-rw-r--r--source/test/worker_pool_test.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/source/test/worker_pool_test.cpp b/source/test/worker_pool_test.cpp
new file mode 100644
index 0000000..73b0f35
--- /dev/null
+++ b/source/test/worker_pool_test.cpp
@@ -0,0 +1,34 @@
+#include "StarWorkerPool.hpp"
+
+#include "gtest/gtest.h"
+
+using namespace Star;
+
+TEST(WorkerPoolTest, All) {
+ int counter = 0;
+ Mutex counterMutex;
+
+ auto incCounter = [&counter, &counterMutex]() {
+ Thread::sleep(100);
+ MutexLocker locker(counterMutex);
+ counter += 1;
+ };
+
+ Deque<WorkerPoolHandle> handles;
+
+ WorkerPool workerPool("WorkerPoolTest");
+ for (size_t i = 0; i < 10; ++i)
+ handles.append(workerPool.addWork(incCounter));
+
+ workerPool.start(10);
+
+ for (size_t i = 0; i < 90; ++i)
+ handles.append(workerPool.addWork(incCounter));
+
+ while (handles.size() > 20)
+ handles.takeFirst().finish();
+
+ workerPool.finish();
+
+ EXPECT_EQ(counter, 100);
+}