Skip to content

Commit fca54dc

Browse files
author
Matt George
committed
changes based on adding some tests.
Still need more tests, but it's a start
1 parent a94eee3 commit fca54dc

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

pyres/horde.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import time, os, signal
88
from pyres.worker import Worker
99
from pyres import ResQ
10+
from pyres.exceptions import NoQueueError
1011
from pyres.utils import OrderedDict
1112
import datetime
1213

@@ -56,11 +57,12 @@ class Khan(object):
5657
def __init__(self, pool_size=5, queues=[], server='localhost:6379', password=None):
5758
#super(Khan,self).__init__(queues=queues,server=server,password=password)
5859
self._shutdown = False
59-
self.pool_size = pool_size
60+
self.pool_size = int(pool_size)
6061
self.queues = queues
6162
self.server = server
6263
self.password = password
6364
self.pid = os.getpid()
65+
self.validate_queues()
6466
if isinstance(server,basestring):
6567
self.resq = ResQ(server=server, password=password)
6668
elif isinstance(server, ResQ):
@@ -69,6 +71,11 @@ def __init__(self, pool_size=5, queues=[], server='localhost:6379', password=Non
6971
raise Exception("Bad server argument")
7072
#self._workers = list()
7173

74+
def validate_queues(self):
75+
"Checks if a worker is given atleast one queue to work on."
76+
if not self.queues:
77+
raise NoQueueError("Please give each worker at least one queue.")
78+
7279
def startup(self):
7380
self.register_signal_handlers()
7481
self.register_worker()

tests/test_horde.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from tests import PyResTests, Basic, TestProcess
2+
from pyres import horde
3+
import os
4+
5+
class KhanTests(PyResTests):
6+
def test_khan_init(self):
7+
from pyres.exceptions import NoQueueError
8+
self.assertRaises(NoQueueError, horde.Khan, 2, [])
9+
self.assertRaises(ValueError, horde.Khan, 'test', ['test'])
10+
self.assertRaises(Exception, horde.Khan, 2, ['test'], TestProcess)
11+
12+
def test_register_worker(self):
13+
khan = horde.Khan(pool_size=1, queues=['basic'])
14+
khan.startup()
15+
name = "%s:%s" % (os.uname()[1],os.getpid())
16+
assert khan.started
17+
assert self.redis.sismember('resque:khans',name)

0 commit comments

Comments
 (0)