MCPcopy Create free account
hub / github.com/ad-freiburg/qlever / TEST

Function TEST

test/ThreadSafeQueueTest.cpp:67–94  ·  view source on GitHub ↗

________________________________________________________________

Source from the content-addressed store, hash-verified

65
66// ________________________________________________________________
67TEST(ThreadSafeQueue, BufferSizeIsRespected) {
68 auto runTest = [](auto queue) {
69 std::atomic<size_t> numPushed = 0;
70 auto push = makePush(queue);
71
72 // Asynchronous worker thread that pushes incremental values to the queue.
73 ad_utility::JThread t([&numPushed, &push, &queue] {
74 while (numPushed < numValues) {
75 push(numPushed++);
76 }
77 queue.finish();
78 });
79
80 size_t numPopped = 0;
81 while (auto opt = queue.pop()) {
82 // We have only one thread pushing, so the elements in the queue are
83 // ordered.
84 EXPECT_EQ(opt.value(), numPopped);
85 ++numPopped;
86 // Check that the size of the queue is respected. The pushing thread must
87 // only continue to push once enough elements have been `pop`ped. The `+1`
88 // is necessary because the calls to `pop` and `push` are not synchronized
89 // with the atomic value `numPushed`.
90 EXPECT_LE(numPushed, numPopped + queueSize + 1);
91 }
92 };
93 runWithBothQueueTypes(runTest);
94}
95
96// _______________________________________________________________
97TEST(ThreadSafeQueue, ReturnValueOfPush) {

Callers

nothing calls this directly

Calls 11

makePushFunction · 0.85
pushFunction · 0.85
runWithBothQueueTypesFunction · 0.85
emplace_backMethod · 0.80
finishMethod · 0.45
popMethod · 0.45
valueMethod · 0.45
push_backMethod · 0.45
pushExceptionMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected