Fix: old task trackers were not really removed

This commit is contained in:
Arik Fraimovich 2016-05-19 09:58:30 +03:00
parent 1a1160eb76
commit b2e2277d0b
2 changed files with 9 additions and 2 deletions

View File

@ -123,7 +123,7 @@ class QueryTaskTracker(object):
remove_count = count - keep_count
keys = redis_connection.zrange(list_name, 0, remove_count - 1)
redis_connection.delete(keys)
redis_connection.delete(*keys)
redis_connection.zremrangebyrank(list_name, 0, remove_count - 1)
return remove_count

View File

@ -7,8 +7,12 @@ class TestPrune(TestCase):
def setUp(self):
self.list = "test_list"
redis_connection.delete(self.list)
self.keys = []
for score in range(0, 100):
redis_connection.zadd(self.list, score, 'k:{}'.format(score))
key = 'k:{}'.format(score)
self.keys.append(key)
redis_connection.zadd(self.list, score, key)
redis_connection.set(key, 1)
def test_does_nothing_when_below_threshold(self):
remove_count = QueryTaskTracker.prune(self.list, 100)
@ -22,3 +26,6 @@ class TestPrune(TestCase):
self.assertEqual(redis_connection.zscore(self.list, 'k:99'), 99.0)
self.assertIsNone(redis_connection.zscore(self.list, 'k:1'))
for k in self.keys[0:50]:
self.assertFalse(redis_connection.exists(k))