From 512a5f8e55ce15e5a3be424f071312933a07d57b Mon Sep 17 00:00:00 2001 From: James Turk Date: Thu, 4 Aug 2011 15:35:16 -0400 Subject: [PATCH] get_update_queue_size now uses counts --- oyster/client.py | 5 ++++- oyster/tests/test_client.py | 27 ++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/oyster/client.py b/oyster/client.py index 96d4c43..ebc83ca 100644 --- a/oyster/client.py +++ b/oyster/client.py @@ -155,4 +155,7 @@ class Client(object): def get_update_queue_size(self): - return len(self.get_update_queue()) + new = self.db.tracked.find({'next_update': {'$exists': False}}).count() + next = self.db.tracked.find({'next_update': + {'$lt': datetime.datetime.utcnow()}}).count() + return new+next diff --git a/oyster/tests/test_client.py b/oyster/tests/test_client.py index 90ac373..e5e5d07 100644 --- a/oyster/tests/test_client.py +++ b/oyster/tests/test_client.py @@ -161,7 +161,7 @@ class ClientTests(TestCase): queue = self.client.get_update_queue() assert len(queue) == 1 - # allow a second to pass + # wait for time to pass time.sleep(1) # queue should be full, but start with the un-updated one @@ -169,3 +169,28 @@ class ClientTests(TestCase): assert len(queue) == 4 assert queue[0]['_id'] == never['_id'] + + def test_get_update_queue_size(self): + self.client.track_url('a', update_mins=0.01) + self.client.track_url('b', update_mins=0.01) + self.client.track_url('c', update_mins=0.01) + + a = self.client.db.tracked.find_one(dict(url='a')) + b = self.client.db.tracked.find_one(dict(url='b')) + c = self.client.db.tracked.find_one(dict(url='c')) + + assert self.client.get_update_queue_size() == 3 + + self.client.update(a) + + assert self.client.get_update_queue_size() == 2 + + self.client.update(b) + self.client.update(c) + + assert self.client.get_update_queue_size() == 0 + + # wait + time.sleep(1) + + assert self.client.get_update_queue_size() == 3