-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_task.py
More file actions
38 lines (30 loc) · 1.01 KB
/
test_task.py
File metadata and controls
38 lines (30 loc) · 1.01 KB
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
import unittest
import time
import threading
import tornado.ioloop
from tasks.task import TASKS
from tasks import task, apply_async
class TestUtils(unittest.TestCase):
def test_task(self):
@task
def t():
pass
target_id = "%s.%s" % (t.__module__, t.__name__)
self.assertEqual(target_id in TASKS, True)
def test_apply_async(self):
@task
def t1(name, value):
self.assertEqual(name == "hello", True)
self.assertEqual(value == "word", True)
@task
def t2(t):
self.assertEqual(time.time() - t > 3, True)
def callback(addr, msg):
self.assertEqual(msg == b'OK', True)
threading.Thread(
target=tornado.ioloop.IOLoop.current().start).start()
time.sleep(3)
apply_async(t1, callback=callback, args=("hello", "word"))
apply_async(t2, callback=callback, delay=3000, args=(time.time(), ))
time.sleep(12)
tornado.ioloop.IOLoop.current().stop()