diff options
author | may <may.hoque@mongodb.com> | 2017-07-18 13:00:00 -0400 |
---|---|---|
committer | may <may.hoque@mongodb.com> | 2017-07-18 13:01:11 -0400 |
commit | 6fb52b5c683765fecd681b0982334f01bb0776c1 (patch) | |
tree | 7346a7b5a2d5fa4cc93441bc7aae2a0eb9e07ed6 /src | |
parent | de836fca3ca8007a8b92fe8718f8b235cdb5b54c (diff) | |
download | mongo-6fb52b5c683765fecd681b0982334f01bb0776c1.tar.gz |
SERVER-29942 Introduce IdempotencyTest::testOpsAreIdempotent() to sync_tail_test to remove boilerplate
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/repl/idempotency_test_fixture.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/repl/idempotency_test_fixture.h | 5 | ||||
-rw-r--r-- | src/mongo/db/repl/sync_tail_test.cpp | 93 |
3 files changed, 27 insertions, 78 deletions
diff --git a/src/mongo/db/repl/idempotency_test_fixture.cpp b/src/mongo/db/repl/idempotency_test_fixture.cpp index 395f9cb06e7..cc8ab2f0ef8 100644 --- a/src/mongo/db/repl/idempotency_test_fixture.cpp +++ b/src/mongo/db/repl/idempotency_test_fixture.cpp @@ -223,6 +223,13 @@ Status IdempotencyTest::runOps(std::initializer_list<OplogEntry> ops) { return multiInitialSyncApply_noAbort(_opCtx.get(), &opsPtrs, &syncTail, &fetchCount); } +void IdempotencyTest::testOpsAreIdempotent(std::initializer_list<OplogEntry> ops) { + ASSERT_OK(runOps(ops)); + auto state = validate(); + ASSERT_OK(runOps(ops)); + ASSERT_EQUALS(state, validate()); +} + OplogEntry IdempotencyTest::createCollection() { return makeCreateCollectionOplogEntry(nextOpTime(), nss); } diff --git a/src/mongo/db/repl/idempotency_test_fixture.h b/src/mongo/db/repl/idempotency_test_fixture.h index 20cc7b574b1..9a53407b4bf 100644 --- a/src/mongo/db/repl/idempotency_test_fixture.h +++ b/src/mongo/db/repl/idempotency_test_fixture.h @@ -91,6 +91,11 @@ protected: } Status runOp(const OplogEntry& entry); Status runOps(std::initializer_list<OplogEntry> ops); + /** + * This method returns true if running the list of operations a single time is equivalent to + * running them two times. It returns false otherwise. + */ + void testOpsAreIdempotent(std::initializer_list<OplogEntry> ops); /** * Validate data and indexes. Return the MD5 hash of the documents ordered by _id. diff --git a/src/mongo/db/repl/sync_tail_test.cpp b/src/mongo/db/repl/sync_tail_test.cpp index df2e4e5e53e..2eb85c4172e 100644 --- a/src/mongo/db/repl/sync_tail_test.cpp +++ b/src/mongo/db/repl/sync_tail_test.cpp @@ -932,11 +932,7 @@ TEST_F(IdempotencyTest, Geo2dsphereIndexFailedOnUpdate) { auto indexOp = buildIndex(fromjson("{loc: '2dsphere'}"), BSON("2dsphereIndexVersion" << 3)); auto ops = {insertOp, updateOp, indexOp}; - - ASSERT_OK(runOps(ops)); - auto state = validate(); - ASSERT_OK(runOps(ops)); - ASSERT_EQUALS(state, validate()); + testOpsAreIdempotent(ops); ASSERT_OK(ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_PRIMARY)); auto status = runOps(ops); @@ -952,11 +948,7 @@ TEST_F(IdempotencyTest, Geo2dsphereIndexFailedOnIndexing) { auto insertOp = insert(fromjson("{_id: 1, loc: 'hi'}")); auto ops = {indexOp, dropIndexOp, insertOp}; - - ASSERT_OK(runOps(ops)); - auto state = validate(); - ASSERT_OK(runOps(ops)); - ASSERT_EQUALS(state, validate()); + testOpsAreIdempotent(ops); ASSERT_OK(ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_PRIMARY)); auto status = runOps(ops); @@ -972,11 +964,7 @@ TEST_F(IdempotencyTest, Geo2dIndex) { auto indexOp = buildIndex(fromjson("{loc: '2d'}")); auto ops = {insertOp, updateOp, indexOp}; - - ASSERT_OK(runOps(ops)); - auto state = validate(); - ASSERT_OK(runOps(ops)); - ASSERT_EQUALS(state, validate()); + testOpsAreIdempotent(ops); ASSERT_OK(ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_PRIMARY)); auto status = runOps(ops); @@ -993,11 +981,7 @@ TEST_F(IdempotencyTest, UniqueKeyIndex) { auto indexOp = buildIndex(fromjson("{x: 1}"), fromjson("{unique: true}")); auto ops = {insertOp, updateOp, insertOp2, indexOp}; - - ASSERT_OK(runOps(ops)); - auto state = validate(); - ASSERT_OK(runOps(ops)); - ASSERT_EQUALS(state, validate()); + testOpsAreIdempotent(ops); ASSERT_OK(ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_PRIMARY)); auto status = runOps(ops); @@ -1017,11 +1001,7 @@ TEST_F(IdempotencyTest, ParallelArrayError) { auto indexOp = buildIndex(fromjson("{x: 1, y: 1}")); auto ops = {updateOp1, updateOp2, updateOp3, indexOp}; - - ASSERT_OK(runOps(ops)); - auto state = validate(); - ASSERT_OK(runOps(ops)); - ASSERT_EQUALS(state, validate()); + testOpsAreIdempotent(ops); ASSERT_OK(ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_PRIMARY)); auto status = runOps(ops); @@ -1044,11 +1024,7 @@ TEST_F(IdempotencyTest, IndexKeyTooLongError) { auto indexOp = buildIndex(fromjson("{x: 1, y: 1}")); auto ops = {updateOp1, updateOp2, updateOp3, indexOp}; - - ASSERT_OK(runOps(ops)); - auto state = validate(); - ASSERT_OK(runOps(ops)); - ASSERT_EQUALS(state, validate()); + testOpsAreIdempotent(ops); ASSERT_OK(ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_PRIMARY)); auto status = runOps(ops); @@ -1067,11 +1043,7 @@ TEST_F(IdempotencyTest, IndexWithDifferentOptions) { auto indexOp2 = buildIndex(fromjson("{x: 'text'}"), fromjson("{default_language: 'english'}")); auto ops = {indexOp1, dropIndexOp, indexOp2}; - - ASSERT_OK(runOps(ops)); - auto state = validate(); - ASSERT_OK(runOps(ops)); - ASSERT_EQUALS(state, validate()); + testOpsAreIdempotent(ops); ASSERT_OK(ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_PRIMARY)); auto status = runOps(ops); @@ -1088,11 +1060,7 @@ TEST_F(IdempotencyTest, TextIndexDocumentHasNonStringLanguageField) { auto indexOp = buildIndex(fromjson("{x: 'text'}"), BSONObj()); auto ops = {insertOp, updateOp, indexOp}; - - ASSERT_OK(runOps(ops)); - auto state = validate(); - ASSERT_OK(runOps(ops)); - ASSERT_EQUALS(state, validate()); + testOpsAreIdempotent(ops); ASSERT_OK(ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_PRIMARY)); auto status = runOps(ops); @@ -1109,11 +1077,7 @@ TEST_F(IdempotencyTest, InsertDocumentWithNonStringLanguageFieldWhenTextIndexExi auto insertOp = insert(fromjson("{_id: 1, x: 'words to index', language: 1}")); auto ops = {indexOp, dropIndexOp, insertOp}; - - ASSERT_OK(runOps(ops)); - auto state = validate(); - ASSERT_OK(runOps(ops)); - ASSERT_EQUALS(state, validate()); + testOpsAreIdempotent(ops); ASSERT_OK(ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_PRIMARY)); auto status = runOps(ops); @@ -1130,11 +1094,7 @@ TEST_F(IdempotencyTest, TextIndexDocumentHasNonStringLanguageOverrideField) { auto indexOp = buildIndex(fromjson("{x: 'text'}"), fromjson("{language_override: 'y'}")); auto ops = {insertOp, updateOp, indexOp}; - - ASSERT_OK(runOps(ops)); - auto state = validate(); - ASSERT_OK(runOps(ops)); - ASSERT_EQUALS(state, validate()); + testOpsAreIdempotent(ops); ASSERT_OK(ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_PRIMARY)); auto status = runOps(ops); @@ -1151,11 +1111,7 @@ TEST_F(IdempotencyTest, InsertDocumentWithNonStringLanguageOverrideFieldWhenText auto insertOp = insert(fromjson("{_id: 1, x: 'words to index', y: 1}")); auto ops = {indexOp, dropIndexOp, insertOp}; - - ASSERT_OK(runOps(ops)); - auto state = validate(); - ASSERT_OK(runOps(ops)); - ASSERT_EQUALS(state, validate()); + testOpsAreIdempotent(ops); ASSERT_OK(ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_PRIMARY)); auto status = runOps(ops); @@ -1172,11 +1128,7 @@ TEST_F(IdempotencyTest, TextIndexDocumentHasUnknownLanguage) { auto indexOp = buildIndex(fromjson("{x: 'text'}"), BSONObj()); auto ops = {insertOp, updateOp, indexOp}; - - ASSERT_OK(runOps(ops)); - auto state = validate(); - ASSERT_OK(runOps(ops)); - ASSERT_EQUALS(state, validate()); + testOpsAreIdempotent(ops); ASSERT_OK(ReplicationCoordinator::get(_opCtx.get())->setFollowerMode(MemberState::RS_PRIMARY)); auto status = runOps(ops); @@ -1195,7 +1147,6 @@ TEST_F(IdempotencyTest, CreateCollectionWithValidation) { auto createColl2 = makeCreateCollectionOplogEntry(nextOpTime(), nss, options2); auto ops = {createColl1, dropColl, createColl2}; - ASSERT_OK(runOps(ops)); auto state = validate(); @@ -1239,7 +1190,6 @@ TEST_F(IdempotencyTest, CreateCollectionWithCollation) { auto createColl = makeCreateCollectionOplogEntry(nextOpTime(), nss, options); auto ops = {insertOp1, insertOp2, updateOp, dropColl, createColl}; - ASSERT_OK(runOps(ops)); auto state = validate(); @@ -1269,7 +1219,6 @@ TEST_F(IdempotencyTest, CreateCollectionWithIdIndex) { auto createColl2 = createCollection(); auto ops = {insertOp, dropColl, createColl2}; - ASSERT_OK(runOps(ops)); auto state = validate(); @@ -1297,11 +1246,7 @@ TEST_F(IdempotencyTest, CreateCollectionWithView) { auto dropColl = makeCommandOplogEntry(nextOpTime(), nss, BSON("drop" << nss.coll())); auto ops = {insertViewOp, dropColl}; - - ASSERT_OK(runOps(ops)); - auto state = validate(); - ASSERT_OK(runOps(ops)); - ASSERT_EQUALS(state, validate()); + testOpsAreIdempotent(ops); } TEST_F(IdempotencyTest, CollModNamespaceNotFound) { @@ -1316,11 +1261,7 @@ TEST_F(IdempotencyTest, CollModNamespaceNotFound) { auto dropCollOp = makeCommandOplogEntry(nextOpTime(), nss, BSON("drop" << nss.coll())); auto ops = {collModOp, dropCollOp}; - - ASSERT_OK(runOps(ops)); - auto state = validate(); - ASSERT_OK(runOps(ops)); - ASSERT_EQUALS(state, validate()); + testOpsAreIdempotent(ops); } TEST_F(IdempotencyTest, CollModIndexNotFound) { @@ -1335,11 +1276,7 @@ TEST_F(IdempotencyTest, CollModIndexNotFound) { auto dropIndexOp = dropIndex("createdAt_index"); auto ops = {collModOp, dropIndexOp}; - - ASSERT_OK(runOps(ops)); - auto state = validate(); - ASSERT_OK(runOps(ops)); - ASSERT_EQUALS(state, validate()); + testOpsAreIdempotent(ops); } TEST_F(IdempotencyTest, ResyncOnRenameCollection) { |