diff options
author | David Storch <david.storch@10gen.com> | 2018-11-28 17:25:24 -0500 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2019-01-15 17:54:33 -0500 |
commit | de2a803ca492261cac1d7f43a9f7c847cd0ea24d (patch) | |
tree | 03cb6ea2b304463e7458f557246a95978d1ef96a /src/mongo/db/repl/collection_cloner_test.cpp | |
parent | af8fa6034f8a989cb47ee890c6a6b3e87e1bcf7b (diff) | |
download | mongo-de2a803ca492261cac1d7f43a9f7c847cd0ea24d.tar.gz |
SERVER-37451 Move all ClientCursor ownership to the global CursorManager.
Deleting the per-collection CursorManagers, and other
related cleanup, is left as future work.
Diffstat (limited to 'src/mongo/db/repl/collection_cloner_test.cpp')
-rw-r--r-- | src/mongo/db/repl/collection_cloner_test.cpp | 94 |
1 files changed, 55 insertions, 39 deletions
diff --git a/src/mongo/db/repl/collection_cloner_test.cpp b/src/mongo/db/repl/collection_cloner_test.cpp index 66fae8cf6d7..3908a8d8501 100644 --- a/src/mongo/db/repl/collection_cloner_test.cpp +++ b/src/mongo/db/repl/collection_cloner_test.cpp @@ -1246,15 +1246,15 @@ protected: /** * Sets up a test for the CollectionCloner that simulates the collection being dropped while - * copying the documents. - * The DBClientConnection returns a CursorNotFound error to indicate a collection drop. + * copying the documents by making a query return the given error code. + * + * The DBClientConnection returns 'code' to indicate a collection drop. */ - void setUpVerifyCollectionWasDroppedTest() { + void setUpVerifyCollectionWasDroppedTest(ErrorCodes::Error code) { // Pause the query so we can reliably wait for it to complete. MockClientPauser pauser(_client); // Return error response from the query. - _client->setFailureForQuery( - {ErrorCodes::CursorNotFound, "collection dropped while copying documents"}); + _client->setFailureForQuery({code, "collection dropped while copying documents"}); ASSERT_OK(collectionCloner->startup()); { executor::NetworkInterfaceMock::InNetworkGuard guard(getNet()); @@ -1284,6 +1284,39 @@ protected: ASSERT_EQUALS(*options.uuid, unittest::assertGet(UUID::parse(firstElement))); return noi; } + + /** + * Start cloning. While copying collection, simulate a collection drop by having the + * DBClientConnection return code 'collectionDropErrCode'. + * + * The CollectionCloner should run a find command on the collection by UUID. Simulate successful + * find command with a drop-pending namespace in the response. The CollectionCloner should + * complete with a successful final status. + */ + void runCloningSuccessfulWithCollectionDropTest(ErrorCodes::Error collectionDropErrCode) { + setUpVerifyCollectionWasDroppedTest(collectionDropErrCode); + + // CollectionCloner should send a find command with the collection's UUID. + { + executor::NetworkInterfaceMock::InNetworkGuard guard(getNet()); + auto noi = getVerifyCollectionDroppedRequest(getNet()); + + // Return a drop-pending namespace in the find response instead of the original + // collection name passed to CollectionCloner at construction. + repl::OpTime dropOpTime(Timestamp(Seconds(100), 0), 1LL); + auto dpns = nss.makeDropPendingNamespace(dropOpTime); + scheduleNetworkResponse(noi, + createCursorResponse(0, dpns.ns(), BSONArray(), "firstBatch")); + finishProcessingNetworkResponse(); + } + + // CollectionCloner treats a in collection state to drop-pending during cloning as a + // successful + // clone operation. + collectionCloner->join(); + ASSERT_OK(getStatus()); + ASSERT_FALSE(collectionCloner->isActive()); + } }; TEST_F(CollectionClonerRenamedBeforeStartTest, FirstRemoteCommandWithRenamedCollection) { @@ -1379,49 +1412,32 @@ TEST_F(CollectionClonerRenamedBeforeStartTest, BeginCollectionWithUUID) { ASSERT_TRUE(collectionCloner->isActive()); } -/** - * Start cloning. - * While copying collection, simulate a collection drop by having the DBClientConnection return a - * CursorNotFound error. - * The CollectionCloner should run a find command on the collection by UUID. - * Simulate successful find command with a drop-pending namespace in the response. - * The CollectionCloner should complete with a successful final status. - */ TEST_F(CollectionClonerRenamedBeforeStartTest, - CloningIsSuccessfulIfCollectionWasDroppedWhileCopyingDocuments) { - setUpVerifyCollectionWasDroppedTest(); - - // CollectionCloner should send a find command with the collection's UUID. - { - executor::NetworkInterfaceMock::InNetworkGuard guard(getNet()); - auto noi = getVerifyCollectionDroppedRequest(getNet()); + CloningIsSuccessfulIfCollectionWasDroppedWithCursorNotFoundWhileCopyingDocuments) { + runCloningSuccessfulWithCollectionDropTest(ErrorCodes::CursorNotFound); +} - // Return a drop-pending namespace in the find response instead of the original collection - // name passed to CollectionCloner at construction. - repl::OpTime dropOpTime(Timestamp(Seconds(100), 0), 1LL); - auto dpns = nss.makeDropPendingNamespace(dropOpTime); - scheduleNetworkResponse(noi, createCursorResponse(0, dpns.ns(), BSONArray(), "firstBatch")); - finishProcessingNetworkResponse(); - } +TEST_F(CollectionClonerRenamedBeforeStartTest, + CloningIsSuccessfulIfCollectionWasDroppedWithOperationFailedWhileCopyingDocuments) { + runCloningSuccessfulWithCollectionDropTest(ErrorCodes::OperationFailed); +} - // CollectionCloner treats a in collection state to drop-pending during cloning as a successful - // clone operation. - collectionCloner->join(); - ASSERT_OK(getStatus()); - ASSERT_FALSE(collectionCloner->isActive()); +TEST_F(CollectionClonerRenamedBeforeStartTest, + CloningIsSuccessfulIfCollectionWasDroppedWithQueryPlanKilledWhileCopyingDocuments) { + runCloningSuccessfulWithCollectionDropTest(ErrorCodes::QueryPlanKilled); } /** - * Start cloning. - * While copying collection, simulate a collection drop by having the DBClientConnection return a - * CursorNotFound error. - * The CollectionCloner should run a find command on the collection by UUID. - * Shut the CollectionCloner down. - * The CollectionCloner should return a CursorNotFound final status. + * Start cloning. While copying collection, simulate a collection drop by having the + * DBClientConnection return a CursorNotFound error. + * + * The CollectionCloner should run a find command on the collection by UUID. Shut the + * CollectionCloner down. The CollectionCloner should return final status corresponding to the + * error code from the DBClientConnection. */ TEST_F(CollectionClonerRenamedBeforeStartTest, ShuttingDownCollectionClonerDuringCollectionDropVerificationReturnsCallbackCanceled) { - setUpVerifyCollectionWasDroppedTest(); + setUpVerifyCollectionWasDroppedTest(ErrorCodes::CursorNotFound); // CollectionCloner should send a find command with the collection's UUID. { |