MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / testThreadPoolErrors

Method testThreadPoolErrors

Tests/Libraries/Threading/ThreadPoolTest.cpp:85–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85void SC::ThreadPoolTest::testThreadPoolErrors()
86{
87 static const size_t numTasks = 4;
88
89 // Define tasks before threadpool to avoid threadpool destructor accessing invalid tasks
90 SC::ThreadPool::Task tasks[numTasks];
91
92 SC::ThreadPool threadPool;
93 SC_TEST_EXPECT(threadPool.create(2));
94 SC::ThreadPool threadPool2;
95 SC_TEST_EXPECT(threadPool2.create(1));
96
97 for (size_t idx = 0; idx < numTasks; idx++)
98 {
99
100 tasks[idx].function = []() { SC::Thread::Sleep(100); };
101 SC_TEST_EXPECT(threadPool.queueTask(tasks[idx]));
102 }
103 // Expect error if trying to add a task to another threadpool
104 SC_TEST_EXPECT(not threadPool2.queueTask(tasks[1]));
105 // Expect error if trying to queue a task again
106 SC_TEST_EXPECT(not threadPool.queueTask(tasks[1]));
107}
108
109namespace SC
110{

Callers

nothing calls this directly

Calls 2

queueTaskMethod · 0.80
createMethod · 0.45

Tested by

no test coverage detected