diff options
author | Lingzhi Deng <lingzhi.deng@mongodb.com> | 2020-02-03 15:18:02 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-02-04 15:24:48 +0000 |
commit | 5b2439ae898613277d8f43ee61542e1c13ac9ca6 (patch) | |
tree | b5fa49ca600339d909d1080b40c9a3a330ef56ff /src/mongo/db/exhaust_cursor_currentop_integration_test.cpp | |
parent | 51af2309a693a71e8842e5f04330df45b9b2538e (diff) | |
download | mongo-5b2439ae898613277d8f43ee61542e1c13ac9ca6.tar.gz |
SERVER-45934: Fix race in ExhaustCursorUpdatesLastKnownCommittedOpTime integration test
Diffstat (limited to 'src/mongo/db/exhaust_cursor_currentop_integration_test.cpp')
-rw-r--r-- | src/mongo/db/exhaust_cursor_currentop_integration_test.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/mongo/db/exhaust_cursor_currentop_integration_test.cpp b/src/mongo/db/exhaust_cursor_currentop_integration_test.cpp index e308109b5c6..162d8a8f8d8 100644 --- a/src/mongo/db/exhaust_cursor_currentop_integration_test.cpp +++ b/src/mongo/db/exhaust_cursor_currentop_integration_test.cpp @@ -363,6 +363,10 @@ TEST(CurrentOpExhaustCursorTest, ExhaustCursorUpdatesLastKnownCommittedOpTime) { &static_cast<DBClientReplicaSet*>(fixtureQueryConn.get())->masterConn(); std::unique_ptr<DBClientCursor> queryCursor; + // Enable a failpoint to block getMore during execution to avoid races between getCursorId() and + // receiving new batches. + setWaitWithPinnedCursorDuringGetMoreBatchFailpoint(conn, true); + // Initiate a tailable awaitData exhaust cursor with lastKnownCommittedOpTime being the // lastAppliedOpTime. auto queryThread = startExhaustQuery(queryConn, @@ -370,13 +374,21 @@ TEST(CurrentOpExhaustCursorTest, ExhaustCursorUpdatesLastKnownCommittedOpTime) { QueryOption_CursorTailable | QueryOption_AwaitData, Milliseconds(1000), // awaitData timeout lastAppliedOpTime); // lastKnownCommittedOpTime + + // Assert non-zero cursorId. + auto cursorId = queryCursor->getCursorId(); + ASSERT_NE(cursorId, 0LL); + + // Disable failpoint and allow exhaust queries to run. + setWaitWithPinnedCursorDuringGetMoreBatchFailpoint(conn, false); + ON_BLOCK_EXIT([&conn, &queryThread] { queryThread.wait(); }); // Test that the cursor's lastKnownCommittedOpTime is eventually advanced to the // lastAppliedOpTime. - auto curOpMatch = BSON("command.collection" - << testNSS.coll() << "command.getMore" << queryCursor->getCursorId() - << "cursor.lastKnownCommittedOpTime" << lastAppliedOpTime); + auto curOpMatch = + BSON("command.collection" << testNSS.coll() << "command.getMore" << cursorId + << "cursor.lastKnownCommittedOpTime" << lastAppliedOpTime); ASSERT(confirmCurrentOpContents(conn, curOpMatch)); // Inserting more records to unblock awaitData and advance the commit point. @@ -392,9 +404,9 @@ TEST(CurrentOpExhaustCursorTest, ExhaustCursorUpdatesLastKnownCommittedOpTime) { // Test that the cursor's lastKnownCommittedOpTime is eventually advanced to the // new lastAppliedOpTime. - curOpMatch = BSON("command.collection" - << testNSS.coll() << "command.getMore" << queryCursor->getCursorId() - << "cursor.lastKnownCommittedOpTime" << lastAppliedOpTime); + curOpMatch = + BSON("command.collection" << testNSS.coll() << "command.getMore" << cursorId + << "cursor.lastKnownCommittedOpTime" << lastAppliedOpTime); ASSERT(confirmCurrentOpContents(conn, curOpMatch)); } } // namespace mongo |