diff --git a/cassandra/timestamps.py b/cassandra/timestamps.py index e9602e16..87cf47b4 100644 --- a/cassandra/timestamps.py +++ b/cassandra/timestamps.py @@ -53,7 +53,7 @@ class MonotonicTimestampGenerator(object): Defaults to 1 second. """ - def __init__(self, warn_on_drift=True, warning_threshold=0, warning_interval=0): + def __init__(self, warn_on_drift=True, warning_threshold=warning_threshold, warning_interval=warning_interval): self.lock = Lock() with self.lock: self.last = 0 @@ -97,7 +97,7 @@ class MonotonicTimestampGenerator(object): since_last_warn = now - self._last_warn warn = (self.warn_on_drift and - (diff > self.warning_threshold * 1e6) and + (diff >= self.warning_threshold * 1e6) and (since_last_warn >= self.warning_interval * 1e6)) if warn: log.warn( diff --git a/tests/unit/test_timestamps.py b/tests/unit/test_timestamps.py index c2f8b93d..67a82a62 100644 --- a/tests/unit/test_timestamps.py +++ b/tests/unit/test_timestamps.py @@ -123,7 +123,10 @@ class TestTimestampGeneratorLogging(unittest.TestCase): @test_category timing """ - tsg = timestamps.MonotonicTimestampGenerator() + tsg = timestamps.MonotonicTimestampGenerator( + warning_threshold=1e-6, + warning_interval=1e-6 + ) #The units of _last_warn is seconds tsg._last_warn = 12 @@ -181,7 +184,8 @@ class TestTimestampGeneratorLogging(unittest.TestCase): @test_category timing """ tsg = timestamps.MonotonicTimestampGenerator( - warning_threshold=1e-6 + warning_threshold=1e-6, + warning_interval=1e-6 ) tsg.last, tsg._last_warn = 100, 97 tsg._next_timestamp(98, tsg.last) @@ -198,6 +202,7 @@ class TestTimestampGeneratorLogging(unittest.TestCase): @test_category timing """ tsg = timestamps.MonotonicTimestampGenerator( + warning_threshold=1e-6, warning_interval=2e-6 ) tsg.last = 100 @@ -219,7 +224,8 @@ class TestTimestampGeneratorLogging(unittest.TestCase): @test_category timing """ tsg = timestamps.MonotonicTimestampGenerator( - warning_interval=1e-6 + warning_interval=1e-6, + warning_threshold=1e-6, ) tsg.last = 100 tsg._next_timestamp(70, tsg.last) @@ -249,7 +255,7 @@ class TestTimestampGeneratorMultipleThreads(unittest.TestCase): with lock: generated_timestamps.append(timestamp) - tsg = timestamps.MonotonicTimestampGenerator(warning_threshold=1) + tsg = timestamps.MonotonicTimestampGenerator() fixed_time = 1 num_threads = 5