Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky CarbonRouterClient.basicUsageSameThreadClient test #458

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions mcrouter/test/cpp_unit_tests/McrouterClientUsage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,28 @@ 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.reset();
EXPECT_TRUE(replyReceived);
Expand Down