MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / TEST

Function TEST

source/test/worker_pool_test.cpp:7–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5using namespace Star;
6
7TEST(WorkerPoolTest, All) {
8 int counter = 0;
9 Mutex counterMutex;
10
11 auto incCounter = [&counter, &counterMutex]() {
12 Thread::sleep(100);
13 MutexLocker locker(counterMutex);
14 counter += 1;
15 };
16
17 Deque<WorkerPoolHandle> handles;
18
19 WorkerPool workerPool("WorkerPoolTest");
20 for (size_t i = 0; i < 10; ++i)
21 handles.append(workerPool.addWork(incCounter));
22
23 workerPool.start(10);
24
25 for (size_t i = 0; i < 90; ++i)
26 handles.append(workerPool.addWork(incCounter));
27
28 while (handles.size() > 20)
29 handles.takeFirst().finish();
30
31 workerPool.finish();
32
33 EXPECT_EQ(counter, 100);
34}

Callers

nothing calls this directly

Calls 6

addWorkMethod · 0.80
appendMethod · 0.45
startMethod · 0.45
sizeMethod · 0.45
finishMethod · 0.45
takeFirstMethod · 0.45

Tested by

no test coverage detected