def test_pop_pending_limit(self): k = pending_key('test') for t in range(5, 40, 5): yield add_pending(self.redis, 'test', { 'owner_id': '1234', 'timestamp': t, 'attempts': 0, 'intervals': [10], 'request': {'foo': t} }) pending = yield zitems(self.redis, k) pending_reqs = [r for t, r in pending] result = yield pop_pending(self.redis, 'test', 0, 50, limit=2) self.assertEqual(result, pending_reqs[:2]) self.assertEqual((yield zitems(self.redis, k)), pending[2:]) result = yield pop_pending(self.redis, 'test', 0, 50, limit=3) self.assertEqual(result, pending_reqs[2:5]) self.assertEqual((yield zitems(self.redis, k)), pending[5:]) result = yield pop_pending(self.redis, 'test', 0, 50, limit=3) self.assertEqual(result, pending_reqs[5:]) self.assertEqual((yield zitems(self.redis, k)), []) result = yield pop_pending(self.redis, 'test', 0, 50, limit=3) self.assertEqual(result, []) self.assertEqual((yield zitems(self.redis, k)), [])
def test_pop_pending_no_deserialize(self): k = pending_key('test') for t in range(5, 35, 5): yield add_pending(self.redis, 'test', { 'owner_id': '1234', 'timestamp': t, 'attempts': 0, 'intervals': [10], 'request': {'foo': t} }) pending = yield zitems(self.redis, k) pending_reqs = [r for t, r in pending] result = yield pop_pending( self.redis, 'test', 0, 10 + 13, deserialize=False) self.assertEqual([json.loads(r) for r in result], pending_reqs[:2])