MCPcopy Create free account
hub / github.com/AshampooSystems/boden / stressTestThread

Function stressTestThread

tests/boden/testDispatchQueue.cpp:163–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161 }
162
163 void stressTestThread(std::weak_ptr<DispatchQueue> dispatchQueue, bool &end, std::atomic<int> &numCalls)
164 {
165 std::this_thread::sleep_for(1ms * rand() % 500);
166
167 std::shared_ptr<int> nCalls = std::make_shared<int>(0);
168 logstream(true) << "BombThread started ( id = 0x" << std::hex << std::this_thread::get_id() << " )";
169 while (!end) {
170 if (auto queue = dispatchQueue.lock())
171 // std::this_thread::sleep_for(1ns * (rand() % 10000));
172 switch (rand() % 3) {
173 case 0:
174 queue->dispatchSync([&numCalls, nCalls]() {
175 numCalls++;
176 (*nCalls)++;
177 });
178 break;
179 case 1:
180 queue->dispatchAsync([&numCalls, nCalls]() {
181 numCalls++;
182 (*nCalls)++;
183 });
184 break;
185 case 2:
186 queue->dispatchAsyncDelayed(1ms * (rand() % 10), [&numCalls, nCalls]() {
187 numCalls++;
188 (*nCalls)++;
189 });
190 break;
191 }
192 }
193
194 logstream(true) << "Thread Id = 0x" << std::hex << std::this_thread::get_id() << " Produced: " << std::dec
195 << *nCalls;
196 }
197
198 TEST(DispatchQueue, StressTest)
199 {

Callers 1

TESTFunction · 0.85

Calls 4

logstreamClass · 0.85
dispatchSyncMethod · 0.80
dispatchAsyncMethod · 0.80
dispatchAsyncDelayedMethod · 0.80

Tested by

no test coverage detected