Skip to content

Commit

Permalink
Fix flaky CarbonRouterClient.basicUsageSameThreadClient test
Browse files Browse the repository at this point in the history
  • Loading branch information
mszabo-wikia committed Dec 19, 2024
1 parent f443398 commit 3a0ef5c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions mcrouter/test/cpp_unit_tests/McrouterClientUsage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,29 @@ TEST(CarbonRouterClient, basicUsageSameThreadClient) {
client->setProxyIndex(0);

bool replyReceived = false;
eventBase.runInEventBaseThread([client = client.get(), &replyReceived]() {
folly::fibers::Baton baton;

eventBase.runInEventBaseThread([client = client.get(), &replyReceived, &baton]() {
// We must ensure that req will remain alive all the way through the reply
// callback given to client->send(). This demonstrates one way of ensuring
// this.
auto req = std::make_unique<McGetRequest>("key");
auto reqRawPtr = req.get();
client->send(
*reqRawPtr,
[req = std::move(req), &replyReceived](
[req = std::move(req), &replyReceived, &baton](
const McGetRequest&, McGetReply&& reply) {
EXPECT_EQ(carbon::Result::NOTFOUND, *reply.result_ref());
replyReceived = true;
baton.post();
});
});

// Wait for proxy threads to complete outstanding requests and exit
// gracefully. This ensures graceful destruction of the static
// CarbonRouterInstance instance.
baton.wait();
router->shutdown();
ioThreadPool->join();
ioThreadPool.reset();
EXPECT_TRUE(replyReceived);
}
Expand Down

0 comments on commit 3a0ef5c

Please sign in to comment.