From fbb3d66a7fdc665c91351730a8fba067fbbbd905 Mon Sep 17 00:00:00 2001 From: Lingzhi Deng Date: Fri, 14 Feb 2020 10:43:20 -0500 Subject: SERVER-46162: Fix race in OplogFetcherAutoReconnectsButFails unit test --- src/mongo/db/repl/oplog_fetcher_test.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/mongo/db/repl/oplog_fetcher_test.cpp b/src/mongo/db/repl/oplog_fetcher_test.cpp index 063f32f0762..352d5954916 100644 --- a/src/mongo/db/repl/oplog_fetcher_test.cpp +++ b/src/mongo/db/repl/oplog_fetcher_test.cpp @@ -2910,11 +2910,21 @@ TEST_F(NewOplogFetcherTest, OplogFetcherAutoReconnectsButFails) { auto oplogFetcher = getOplogFetcherAfterConnectionCreated(std::ref(shutdownState), 1); auto conn = oplogFetcher->getDBClientConnection_forTest(); - // Shut down the mock server and simulate a disconnect for the first find command. And the - // OplogFetcher should retry with AutoReconnect. - _mockServer->shutdown(); + + auto beforeRecreatingCursor = globalFailPointRegistry().find("hangBeforeOplogFetcherRetries"); + auto timesEntered = beforeRecreatingCursor->setMode(FailPoint::alwaysOn); + + // Simulate a disconnect for the first find command. And the OplogFetcher should retry with + // AutoReconnect. simulateNetworkDisconnect(conn); + // Shut down the mock server before OplogFetcher reconnects. + beforeRecreatingCursor->waitForTimesEntered(timesEntered + 1); + _mockServer->shutdown(); + + // Allow retry and autoreconnect. + beforeRecreatingCursor->setMode(FailPoint::off); + oplogFetcher->join(); // AutoReconnect should also fail because the server is shut down. -- cgit v1.2.1