Пример #1
0
 def testNoCount(self):
     mock_time = _MockTime()
     counter = counter_lib._SingleThreadCounter(
         duration=datetime.timedelta(seconds=10),
         time_func=mock_time.get_time)
     self.assertEqual(counter.get(), 0)
     mock_time.set_offset(5)
     self.assertEqual(counter.get(), 0)
     mock_time.set_offset(15)
     self.assertEqual(counter.get(), 0)
Пример #2
0
 def testMultipleCountOverLongPeriod(self):
     mock_time = _MockTime()
     counter = counter_lib._SingleThreadCounter(
         duration=datetime.timedelta(seconds=10),
         time_func=mock_time.get_time)
     counter.add()
     mock_time.set_offset(20)
     counter.add()
     self.assertEqual(counter.get(), 1)
     mock_time.set_offset(29)
     self.assertEqual(counter.get(), 1)
     mock_time.set_offset(30)
     self.assertEqual(counter.get(), 0)
Пример #3
0
 def testMultipleCountInSameBucket(self):
     mock_time = _MockTime()
     counter = counter_lib._SingleThreadCounter(
         duration=datetime.timedelta(seconds=10),
         time_func=mock_time.get_time)
     mock_time.set_offset(5)
     counter.add()
     counter.add()
     counter.add()
     self.assertEqual(counter.get(), 3)
     mock_time.set_offset(14)
     self.assertEqual(counter.get(), 3)
     mock_time.set_offset(15)
     self.assertEqual(counter.get(), 0)