This commit is contained in:
Aria 2025-03-21 22:23:30 +11:00
commit 9c94d113d3
Signed by untrusted user who does not match committer: aria
GPG key ID: 19AB7AA462B8AB3B
10260 changed files with 1237388 additions and 0 deletions

View file

@ -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);
}