Skip to content

Commit

Permalink
Fix: bmqimp_brokersession.t.cpp unit test thread race
Browse files Browse the repository at this point in the history
* Fixed incorrect check for empty write calls after async Configure (must be non-empty after a small timeout)

* Fixed incorrect absolute timestamp for timedPopFront when waiting for events

Signed-off-by: Evgeny Malygin <[email protected]>
  • Loading branch information
678098 authored Aug 4, 2023
1 parent 1ee55e5 commit ca6491f
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/groups/bmq/bmqimp/bmqimp_brokersession.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2242,7 +2242,6 @@ bool TestSession::waitForQueueRemoved(

const bsls::TimeInterval expireAfter =
bsls::SystemTime::nowRealtimeClock() + timeout;
mwcsys::Time::nowMonotonicClock() + timeout;
while (session().lookupQueue(queue->uri()) != 0 &&
bsls::SystemTime::nowRealtimeClock() < expireAfter) {
bslmt::ThreadUtil::microSleep(k_TIME_SOURCE_STEP.totalMicroseconds());
Expand Down Expand Up @@ -9795,11 +9794,10 @@ static void test54_distributedTrace()
// with the given default timeout.
buffer.resize(expectedNum);
for (size_t i = 0; i < expectedNum; i++) {
ASSERT_EQ(
events.timedPopFront(&buffer[i],
mwcsys::Time::nowMonotonicClock() +
bsls::TimeInterval(0.1)),
0);
ASSERT_EQ(events.timedPopFront(&buffer[i],
bdlt::CurrentTime::now() +
bsls::TimeInterval(0.1)),
0);
}

addSpacer(events);
Expand All @@ -9812,10 +9810,27 @@ static void test54_distributedTrace()
// Make sure no other events arrive with the given default timeout.
bsl::string emptyStr(s_allocator_p);
ASSERT_NE(events.timedPopFront(&emptyStr,
mwcsys::Time::nowMonotonicClock() +
bdlt::CurrentTime::now() +
bsls::TimeInterval(0.01)),
0);
}

static bool waitForWriteCall(
const bsl::deque<mwcio::TestChannel::WriteCall>& calls,
const bsls::TimeInterval& timeout)
{
PVVV_SAFE("Waiting for any write event");

const bsls::TimeInterval expireAfter =
bsls::SystemTime::nowRealtimeClock() + timeout;
while (calls.empty() &&
bsls::SystemTime::nowRealtimeClock() < expireAfter) {
bslmt::ThreadUtil::microSleep(
TestSession::k_TIME_SOURCE_STEP.totalMicroseconds());
}

return !calls.empty();
}
};

bsl::vector<bsl::string> dtEvents(s_allocator_p);
Expand Down Expand Up @@ -9908,11 +9923,13 @@ static void test54_distributedTrace()
dtEvents.clear();

PVV_SAFE("Step 3. Configure a queue");
ASSERT(obj.channel().writeCalls().empty());
int rc = obj.session().configureQueueAsync(pQueue,
pQueue->options(),
timeout);
ASSERT_EQ(rc, bmqt::ConfigureQueueResult::e_SUCCESS);
ASSERT(obj.channel().writeCalls().empty());
ASSERT(localFns::waitForWriteCall(obj.channel().writeCalls(),
bsls::TimeInterval(0.1)));

localFns::fillEventBufferFn(dtEvents, dtEventsQueue, 1u);
ASSERT_EQ(dtEvents[0],
Expand Down

0 comments on commit ca6491f

Please sign in to comment.