예제 #1
0
파일: test_storage.py 프로젝트: er0k/limits
 def test_expiry(self):
     with hiro.Timeline().freeze() as timeline:
         limiter = FixedWindowRateLimiter(self.storage)
         per_min = RateLimitItemPerMinute(10)
         for i in range(0, 10):
             self.assertTrue(limiter.hit(per_min))
         timeline.forward(60)
         # touch another key and yield
         limiter.hit(RateLimitItemPerSecond(1))
         time.sleep(0.1)
         self.assertTrue(per_min.key_for() not in self.storage.storage)
예제 #2
0
 def test_in_memory_expiry(self):
     with hiro.Timeline().freeze() as timeline:
         storage = MemoryStorage()
         limiter = FixedWindowRateLimiter(storage)
         per_min = RateLimitItemPerMinute(10)
         for i in range(0,10):
             self.assertTrue(limiter.hit(per_min))
         timeline.forward(60)
         # touch another key and yield
         limiter.hit(RateLimitItemPerSecond(1))
         time.sleep(0.1)
         self.assertTrue(per_min.key_for() not in storage.storage)
예제 #3
0
 def test_in_memory_expiry_moving_window(self):
     with hiro.Timeline().freeze() as timeline:
         storage = MemoryStorage()
         limiter = MovingWindowRateLimiter(storage)
         per_min = RateLimitItemPerMinute(10)
         per_sec = RateLimitItemPerSecond(1)
         for i in range(0,2):
             for i in range(0,10):
                 self.assertTrue(limiter.hit(per_min))
             timeline.forward(60)
             self.assertTrue(limiter.hit(per_sec))
             time.sleep(1)
             self.assertEqual([], storage.events[per_min.key_for()])
예제 #4
0
 def test_in_memory_expiry_moving_window(self):
     with hiro.Timeline().freeze() as timeline:
         storage = MemoryStorage()
         limiter = MovingWindowRateLimiter(storage)
         per_min = RateLimitItemPerMinute(10)
         per_sec = RateLimitItemPerSecond(1)
         for i in range(0, 2):
             for i in range(0, 10):
                 self.assertTrue(limiter.hit(per_min))
             timeline.forward(60)
             self.assertTrue(limiter.hit(per_sec))
             time.sleep(1)
             self.assertEqual([], storage.events[per_min.key_for()])