Skip to content

Commit

Permalink
Add test flow to exercise get/get_expiry of redis storage
Browse files Browse the repository at this point in the history
  • Loading branch information
alisaifee committed Oct 5, 2015
1 parent b204b45 commit cda919c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
3 changes: 1 addition & 2 deletions limits/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,9 @@ def get_client(self, module, hosts):
def call_memcached_func(self, func, *args, **kwargs):
if 'noreply' in kwargs:
if 'noreply' not in inspect.getargspec(func).args:
kwargs.pop('noreply')
kwargs.pop('noreply') # noqa
return func(*args, **kwargs)


@property
def storage(self):
"""
Expand Down
23 changes: 18 additions & 5 deletions tests/test_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

from limits.limits import RateLimitItemPerSecond, RateLimitItemPerMinute
from limits.storage import (
MemoryStorage, RedisStorage,MemcachedStorage
)
MemoryStorage, RedisStorage,MemcachedStorage,
RedisSentinelStorage)
from limits.strategies import (
MovingWindowRateLimiter,
FixedWindowElasticExpiryRateLimiter,
Expand Down Expand Up @@ -95,6 +95,21 @@ def test_fixed_window_with_elastic_expiry_redis(self):
self.assertFalse(limiter.hit(limit))
time.sleep(1)
self.assertFalse(limiter.hit(limit))
self.assertEqual(limiter.get_window_stats(limit)[1], 0)

def test_fixed_window_with_elastic_expiry_redis_sentinel(self):
storage = RedisSentinelStorage(
"redis+sentinel://localhost:26379",
service_name="localhost-redis-sentinel"
)
limiter = FixedWindowElasticExpiryRateLimiter(storage)
limit = RateLimitItemPerSecond(10, 2)
self.assertTrue(all([limiter.hit(limit) for _ in range(0,10)]))
time.sleep(1)
self.assertFalse(limiter.hit(limit))
time.sleep(1)
self.assertFalse(limiter.hit(limit))
self.assertEqual(limiter.get_window_stats(limit)[1], 0)

def test_moving_window_in_memory(self):
storage = MemoryStorage()
Expand Down Expand Up @@ -132,12 +147,10 @@ def test_moving_window_redis(self):
self.assertTrue(limiter.hit(limit))
self.assertEqual(limiter.get_window_stats(limit)[1], 0)

def xest_moving_window_memcached(self):
def test_moving_window_memcached(self):
storage = MemcachedStorage('memcacheD://localhost:11211')
self.assertRaises(NotImplementedError, MovingWindowRateLimiter, storage)



def test_test_fixed_window(self):
with hiro.Timeline().freeze() as timeline:
store = MemoryStorage()
Expand Down

0 comments on commit cda919c

Please sign in to comment.