-
Notifications
You must be signed in to change notification settings - Fork 2
/
tests.py
56 lines (46 loc) · 2.04 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import time
import unittest
from dreque import Dreque, DrequeWorker
something = None
def set_something(val):
global something
something = val
class TestDreque(unittest.TestCase):
def setUp(self):
import logging
logging.basicConfig(level=logging.DEBUG)
self.dreque = Dreque("127.0.0.1")
self.queue = "test"
self.dreque.remove_queue(self.queue)
def tearDown(self):
pass
def testSimple(self):
self.dreque.push("test", "foo")
self.failUnlessEqual(self.dreque.pop("test"), "foo")
self.failUnlessEqual(self.dreque.pop("test"), None)
def testFunction(self):
import tests
self.dreque.enqueue("test", tests.set_something, "positional")
self.failUnlessEqual(self.dreque.dequeue(["test"]), dict(queue="test", func="tests.set_something", args=["positional"], kwargs={}))
self.dreque.enqueue("test", tests.set_something, keyword="argument")
self.failUnlessEqual(self.dreque.dequeue(["test"]), dict(queue="test", func="tests.set_something", args=[], kwargs={'keyword':"argument"}))
def testPositionalWorker(self):
import tests
self.dreque.enqueue("test", tests.set_something, "worker_test")
worker = DrequeWorker(["test"], "127.0.0.1", nofork=True)
worker.work(0)
self.failUnlessEqual(tests.something, "worker_test")
def testKeywordWorker(self):
import tests
self.dreque.enqueue("test", tests.set_something, val="worker_test")
worker = DrequeWorker(["test"], "127.0.0.1", nofork=True)
worker.work(0)
self.failUnlessEqual(tests.something, "worker_test")
def testDelayedJob(self):
import tests
self.dreque.enqueue("test", tests.set_something, val="worker_test", _delay=1)
self.failUnlessEqual(self.dreque.dequeue("test"), None)
time.sleep(1.5)
self.failUnlessEqual(self.dreque.dequeue(["test"]), dict(queue="test", func="tests.set_something", args=[], kwargs={'val':"worker_test"}))
if __name__ == '__main__':
unittest.main()