blob: 73b0f35dd736c1595fc7bbee5910a84a9f076936 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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);
}
|