summaryrefslogtreecommitdiff
path: root/src/mongo/db/logical_time_validator_test.cpp
diff options
context:
space:
mode:
authorJack Mulrow <jack.mulrow@mongodb.com>2017-06-15 18:19:42 -0400
committerJack Mulrow <jack.mulrow@mongodb.com>2017-06-22 10:09:12 -0400
commit0d79ab8b66fcaf06bf5622de580ed5a85c95bc16 (patch)
tree688fa34e05a158020f8f28e8d1891b95d4ddbacb /src/mongo/db/logical_time_validator_test.cpp
parent67d75157ae993359575e5fb567557d82b016877e (diff)
downloadmongo-0d79ab8b66fcaf06bf5622de580ed5a85c95bc16.tar.gz
SERVER-29652 mongos should not gossip logical time until admin.system.keys is created
Diffstat (limited to 'src/mongo/db/logical_time_validator_test.cpp')
-rw-r--r--src/mongo/db/logical_time_validator_test.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/mongo/db/logical_time_validator_test.cpp b/src/mongo/db/logical_time_validator_test.cpp
index 2aeb11462a8..fca439630fb 100644
--- a/src/mongo/db/logical_time_validator_test.cpp
+++ b/src/mongo/db/logical_time_validator_test.cpp
@@ -85,6 +85,20 @@ protected:
}
/**
+ * Replaces the test's LogicalTimeValidator with a new one with a disabled keyGenerator.
+ */
+ void resetValidator() {
+ _validator->shutDown();
+
+ auto catalogClient = Grid::get(operationContext())->catalogClient(operationContext());
+ auto keyManager =
+ stdx::make_unique<KeysCollectionManager>("dummy", catalogClient, Seconds(1000));
+ _keyManager = keyManager.get();
+ _validator = stdx::make_unique<LogicalTimeValidator>(std::move(keyManager));
+ _validator->init(operationContext()->getServiceContext());
+ }
+
+ /**
* Forces KeyManager to refresh cache and generate new keys.
*/
void refreshKeyManager() {
@@ -150,5 +164,32 @@ TEST_F(LogicalTimeValidatorTest, ValidateErrorsOnInvalidTimeWithImplicitRefresh)
ASSERT_EQ(ErrorCodes::TimeProofMismatch, status);
}
+TEST_F(LogicalTimeValidatorTest, ShouldGossipLogicalTimeIsFalseUntilKeysAreFound) {
+ // Use a new validator with a disabled key generator.
+ resetValidator();
+
+ // shouldGossipLogicalTime initially returns false.
+ ASSERT_EQ(false, validator()->shouldGossipLogicalTime());
+
+ // Enable key generation.
+ validator()->enableKeyGenerator(operationContext(), true);
+
+ // shouldGossipLogicalTime still returns false after an unsuccessful refresh.
+ validator()->enableKeyGenerator(operationContext(), false);
+ refreshKeyManager();
+
+ LogicalTime t1(Timestamp(20, 0));
+ validator()->trySignLogicalTime(t1);
+ ASSERT_EQ(false, validator()->shouldGossipLogicalTime());
+
+ // Once keys are successfully found, shouldGossipLogicalTime returns true.
+ validator()->enableKeyGenerator(operationContext(), true);
+ refreshKeyManager();
+ auto newTime = validator()->signLogicalTime(operationContext(), t1);
+
+ ASSERT_EQ(true, validator()->shouldGossipLogicalTime());
+ ASSERT_OK(validator()->validate(operationContext(), newTime));
+}
+
} // unnamed namespace
} // namespace mongo