diff options
author | Benety Goh <benety@mongodb.com> | 2018-03-29 11:34:19 -0400 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2018-03-29 13:41:58 -0400 |
commit | c2d54f70ad7b23bba86776f60504dc4916dead27 (patch) | |
tree | 0b508802d6072cf9aaec946391333096d73e8981 /src/mongo/db/catalog/rename_collection_test.cpp | |
parent | 6306b96749d4a547a1fa023eb1a0085b37e75c07 (diff) | |
download | mongo-c2d54f70ad7b23bba86776f60504dc4916dead27.tar.gz |
SERVER-33956 add renameCollection characterization test case for dropTarget=true
This test case demonstrates the current behavior when the target collection does
not exist.
Diffstat (limited to 'src/mongo/db/catalog/rename_collection_test.cpp')
-rw-r--r-- | src/mongo/db/catalog/rename_collection_test.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/mongo/db/catalog/rename_collection_test.cpp b/src/mongo/db/catalog/rename_collection_test.cpp index 7802ccffdab..068cd83e468 100644 --- a/src/mongo/db/catalog/rename_collection_test.cpp +++ b/src/mongo/db/catalog/rename_collection_test.cpp @@ -110,6 +110,7 @@ public: bool onInsertsIsGlobalWriteLockExclusive = false; bool onRenameCollectionCalled = false; + bool onRenameCollectionDropTarget = false; repl::OpTime renameOpTime = {Timestamp(Seconds(100), 1U), 1LL}; private: @@ -179,6 +180,7 @@ repl::OpTime OpObserverMock::onRenameCollection(OperationContext* opCtx, OpObserverNoop::onRenameCollection( opCtx, fromCollection, toCollection, uuid, dropTarget, dropTargetUUID, stayTemp); onRenameCollectionCalled = true; + onRenameCollectionDropTarget = dropTarget; return {}; } @@ -675,6 +677,7 @@ TEST_F(RenameCollectionTest, RenameCollectionMakesTargetCollectionDropPendingIfD << " missing after successful rename"; ASSERT_TRUE(_opObserver->onRenameCollectionCalled); + ASSERT_TRUE(_opObserver->onRenameCollectionDropTarget); auto renameOpTime = _opObserver->renameOpTime; ASSERT_GREATER_THAN(renameOpTime, repl::OpTime()); @@ -686,6 +689,21 @@ TEST_F(RenameCollectionTest, RenameCollectionMakesTargetCollectionDropPendingIfD << " not renamed to drop-pending collection after successful rename"; } +TEST_F(RenameCollectionTest, + RenameCollectionRetainsDropTargetIfTargetCollectionIsMissingAndDropTargetIsTrue) { + _createCollectionWithUUID(_opCtx.get(), _sourceNss); + RenameCollectionOptions options; + options.dropTarget = true; + ASSERT_OK(renameCollection(_opCtx.get(), _sourceNss, _targetNss, options)); + ASSERT_FALSE(_collectionExists(_opCtx.get(), _sourceNss)) + << "source collection " << _sourceNss << " still exists after successful rename"; + ASSERT_TRUE(_collectionExists(_opCtx.get(), _targetNss)) << "target collection " << _targetNss + << " missing after successful rename"; + + ASSERT_TRUE(_opObserver->onRenameCollectionCalled); + ASSERT_TRUE(_opObserver->onRenameCollectionDropTarget); +} + TEST_F(RenameCollectionTest, RenameCollectionForApplyOpsRejectsRenameOpTimeIfWritesAreReplicated) { ASSERT_TRUE(_opCtx->writesAreReplicated()); |