diff options
author | Lingzhi Deng <lingzhi.deng@mongodb.com> | 2019-05-23 16:23:39 -0400 |
---|---|---|
committer | Lingzhi Deng <lingzhi.deng@mongodb.com> | 2019-05-29 14:37:22 -0400 |
commit | d0501d6c8497aa110f39fba726678cab4e47bafc (patch) | |
tree | d1bc2630bd4965e69b51bcf88f6e962ae72b88ee /src | |
parent | cb45824b458c1b3714a379c5c658e1e89238c03d (diff) | |
download | mongo-d0501d6c8497aa110f39fba726678cab4e47bafc.tar.gz |
SERVER-36538: fix idempotency test prefix/suffix test
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/repl/idempotency_test.cpp | 24 | ||||
-rw-r--r-- | src/mongo/db/repl/idempotency_test_fixture.cpp | 45 | ||||
-rw-r--r-- | src/mongo/db/repl/idempotency_test_fixture.h | 10 |
3 files changed, 35 insertions, 44 deletions
diff --git a/src/mongo/db/repl/idempotency_test.cpp b/src/mongo/db/repl/idempotency_test.cpp index 6ca379bfe64..e76599bc86a 100644 --- a/src/mongo/db/repl/idempotency_test.cpp +++ b/src/mongo/db/repl/idempotency_test.cpp @@ -58,9 +58,9 @@ protected: BSONObj getDoc(); - std::string getStateString(const CollectionState& state1, - const CollectionState& state2, - const std::vector<OplogEntry>& ops) override; + std::string getStatesString(const std::vector<CollectionState>& state1, + const std::vector<CollectionState>& state2, + const MultiApplier::OperationPtrs& opPtrs) override; Status resetState() override; @@ -111,30 +111,30 @@ std::vector<OplogEntry> RandomizedIdempotencyTest::createUpdateSequence( return updateSequence; } -std::string RandomizedIdempotencyTest::getStateString(const CollectionState& state1, - const CollectionState& state2, - const std::vector<OplogEntry>& ops) { - unittest::log() << IdempotencyTest::getStateString(state1, state2, ops); +std::string RandomizedIdempotencyTest::getStatesString(const std::vector<CollectionState>& state1, + const std::vector<CollectionState>& state2, + const MultiApplier::OperationPtrs& opPtrs) { + unittest::log() << IdempotencyTest::getStatesString(state1, state2, opPtrs); StringBuilder sb; sb << "Ran update ops: "; sb << "[ "; bool firstIter = true; - for (auto op : ops) { + for (auto op : opPtrs) { if (!firstIter) { sb << ", "; } else { firstIter = false; } - sb << op.toString(); + sb << op->toString(); } sb << " ]\n"; ASSERT_OK(resetState()); sb << "Start: " << getDoc() << "\n"; - for (auto op : ops) { - ASSERT_OK(runOpInitialSync(op)); - sb << "Apply: " << op.getObject() << "\n ==> " << getDoc() << "\n"; + for (auto op : opPtrs) { + ASSERT_OK(runOpInitialSync(*op)); + sb << "Apply: " << op->getObject() << "\n ==> " << getDoc() << "\n"; } sb << "Found from the seed: " << this->seed; diff --git a/src/mongo/db/repl/idempotency_test_fixture.cpp b/src/mongo/db/repl/idempotency_test_fixture.cpp index 3a84112a1ad..08fd12b274b 100644 --- a/src/mongo/db/repl/idempotency_test_fixture.cpp +++ b/src/mongo/db/repl/idempotency_test_fixture.cpp @@ -401,31 +401,31 @@ void IdempotencyTest::testOpsAreIdempotent(std::vector<OplogEntry> ops, Sequence // we don't drop and re-create the collections. Dropping and re-creating the collections // won't work either because we don't have ways to wait until second-phase drop to // completely finish. - std::vector<OplogEntry> fullSequence; + MultiApplier::OperationPtrs fullSequence; if (sequenceType == SequenceType::kEntireSequence) { ASSERT_OK(runOpPtrsInitialSync(opPtrs)); - fullSequence.insert(fullSequence.end(), ops.begin(), ops.end()); + fullSequence.insert(fullSequence.end(), opPtrs.begin(), opPtrs.end()); } else if (sequenceType == SequenceType::kAnyPrefix || sequenceType == SequenceType::kAnyPrefixOrSuffix) { - std::vector<OplogEntry> prefix(ops.begin(), ops.begin() + i + 1); - ASSERT_OK(runOpPtrsInitialSync(opPtrs)); + MultiApplier::OperationPtrs prefix(opPtrs.begin(), opPtrs.begin() + i + 1); + ASSERT_OK(runOpPtrsInitialSync(prefix)); fullSequence.insert(fullSequence.end(), prefix.begin(), prefix.end()); } ASSERT_OK(runOpPtrsInitialSync(opPtrs)); - fullSequence.insert(fullSequence.end(), ops.begin(), ops.end()); + fullSequence.insert(fullSequence.end(), opPtrs.begin(), opPtrs.end()); if (sequenceType == SequenceType::kAnySuffix || sequenceType == SequenceType::kAnyPrefixOrSuffix) { - std::vector<OplogEntry> suffix(ops.begin() + i, ops.end()); - ASSERT_OK(runOpPtrsInitialSync(opPtrs)); + MultiApplier::OperationPtrs suffix(opPtrs.begin() + i, opPtrs.end()); + ASSERT_OK(runOpPtrsInitialSync(suffix)); fullSequence.insert(fullSequence.end(), suffix.begin(), suffix.end()); } auto state2 = validateAllCollections(); if (state1 != state2) { - FAIL(getStateVectorString(state1, state2, fullSequence)); + FAIL(getStatesString(state1, state2, fullSequence)); } } } @@ -634,28 +634,23 @@ CollectionState IdempotencyTest::validate(const NamespaceString& nss) { return collectionState; } -std::string IdempotencyTest::getStateString(const CollectionState& state1, - const CollectionState& state2, - const std::vector<OplogEntry>& ops) { +std::string IdempotencyTest::getStatesString(const std::vector<CollectionState>& state1, + const std::vector<CollectionState>& state2, + const MultiApplier::OperationPtrs& opPtrs) { StringBuilder sb; - sb << "The state: " << state1 << " does not match with the state: " << state2 - << " found after applying the operations a second time, therefore breaking idempotency."; - return sb.str(); -} - -std::string IdempotencyTest::getStateVectorString(std::vector<CollectionState>& state1, - std::vector<CollectionState>& state2, - const std::vector<OplogEntry>& ops) { - StringBuilder sb; - sb << "The states: "; + sb << "The states:\n"; for (const auto& s : state1) { - sb << s << " "; + sb << s << "\n"; } - sb << "do not match with the states: "; + sb << "do not match with the states:\n"; for (const auto& s : state2) { - sb << s << " "; + sb << s << "\n"; + } + sb << "found after applying the operations a second time, therefore breaking idempotency.\n"; + sb << "Applied ops:\n"; + for (auto op : opPtrs) { + sb << op->toString() << "\n"; } - sb << " found after applying the operations a second time, therefore breaking idempotency."; return sb.str(); } diff --git a/src/mongo/db/repl/idempotency_test_fixture.h b/src/mongo/db/repl/idempotency_test_fixture.h index 82eb4215b59..5443e79ce4d 100644 --- a/src/mongo/db/repl/idempotency_test_fixture.h +++ b/src/mongo/db/repl/idempotency_test_fixture.h @@ -140,13 +140,9 @@ protected: }; std::string computeDataHash(Collection* collection); - virtual std::string getStateString(const CollectionState& state1, - const CollectionState& state2, - const std::vector<OplogEntry>& ops); - - virtual std::string getStateVectorString(std::vector<CollectionState>& state1, - std::vector<CollectionState>& state2, - const std::vector<OplogEntry>& ops); + virtual std::string getStatesString(const std::vector<CollectionState>& state1, + const std::vector<CollectionState>& state2, + const MultiApplier::OperationPtrs& opPtrs); /** * Validate data and indexes. Return the MD5 hash of the documents ordered by _id. */ |