summaryrefslogtreecommitdiff
path: root/src/mongo/db/logical_clock_test.cpp
diff options
context:
space:
mode:
authorJack Mulrow <jack.mulrow@mongodb.com>2017-03-15 12:13:35 -0400
committerJack Mulrow <jack.mulrow@mongodb.com>2017-03-17 10:38:11 -0400
commit9c47a56c17f9c155f7794c09020893bfa80cb05d (patch)
treeb24fc3fdc51ce9438897e7492682d5162797cc04 /src/mongo/db/logical_clock_test.cpp
parent9e7974e4b6e2b3fe5e7741dce6549624113af196 (diff)
downloadmongo-9c47a56c17f9c155f7794c09020893bfa80cb05d.tar.gz
SERVER-27721 Implement rate limiter check for advancing logical clocks
Diffstat (limited to 'src/mongo/db/logical_clock_test.cpp')
-rw-r--r--src/mongo/db/logical_clock_test.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/mongo/db/logical_clock_test.cpp b/src/mongo/db/logical_clock_test.cpp
index bb8bdba9afc..a0b8dbaf30e 100644
--- a/src/mongo/db/logical_clock_test.cpp
+++ b/src/mongo/db/logical_clock_test.cpp
@@ -66,6 +66,11 @@ protected:
return SignedLogicalTime(logicalTime, _timeProofService->getProof(logicalTime));
}
+ const unsigned currentWallClockSecs() {
+ return durationCount<Seconds>(
+ _serviceContext->getFastClockSource()->now().toDurationSinceEpoch());
+ }
+
private:
TimeProofService* _timeProofService;
std::unique_ptr<ServiceContextNoop> _serviceContext;
@@ -118,5 +123,30 @@ TEST_F(LogicalClockTestBase, advanceClusterTime) {
ASSERT_TRUE(l1.getTime() == l2.getTime());
}
+// Verify rate limiter rejects logical times whose seconds values are too far ahead.
+TEST_F(LogicalClockTestBase, RateLimiterRejectsLogicalTimesTooFarAhead) {
+ Timestamp tooFarAheadTimestamp(
+ currentWallClockSecs() +
+ durationCount<Seconds>(LogicalClock::kMaxAcceptableLogicalClockDrift) +
+ 10, // Add 10 seconds to ensure limit is exceeded.
+ 1);
+ SignedLogicalTime l1 = makeSignedLogicalTime(LogicalTime(tooFarAheadTimestamp));
+
+ ASSERT_EQ(ErrorCodes::ClusterTimeFailsRateLimiter, getClock()->advanceClusterTime(l1));
+ ASSERT_EQ(ErrorCodes::ClusterTimeFailsRateLimiter,
+ getClock()->advanceClusterTimeFromTrustedSource(l1));
+}
+
+// Verify cluster time can be initialized to a very old time.
+TEST_F(LogicalClockTestBase, InitFromTrustedSourceCanAcceptVeryOldLogicalTime) {
+ Timestamp veryOldTimestamp(
+ currentWallClockSecs() -
+ (durationCount<Seconds>(LogicalClock::kMaxAcceptableLogicalClockDrift) * 5));
+ auto veryOldTime = LogicalTime(veryOldTimestamp);
+ getClock()->initClusterTimeFromTrustedSource(veryOldTime);
+
+ ASSERT_TRUE(getClock()->getClusterTime().getTime() == veryOldTime);
+}
+
} // unnamed namespace
} // namespace mongo