From 0d79ab8b66fcaf06bf5622de580ed5a85c95bc16 Mon Sep 17 00:00:00 2001 From: Jack Mulrow Date: Thu, 15 Jun 2017 18:19:42 -0400 Subject: SERVER-29652 mongos should not gossip logical time until admin.system.keys is created --- src/mongo/db/logical_time_validator_test.cpp | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/mongo/db/logical_time_validator_test.cpp') 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 @@ -84,6 +84,20 @@ protected: return stdx::make_unique(std::move(distLockCatalog)); } + /** + * 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("dummy", catalogClient, Seconds(1000)); + _keyManager = keyManager.get(); + _validator = stdx::make_unique(std::move(keyManager)); + _validator->init(operationContext()->getServiceContext()); + } + /** * Forces KeyManager to refresh cache and generate new keys. */ @@ -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 -- cgit v1.2.1