Skip to content

Commit 23742d8

Browse files
committed
fix(tests): fix test_task.py run error
1 parent dd5bb66 commit 23742d8

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

rootfs/tasks/tests/test_task.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22
import time
3-
import threading
3+
import datetime
44
import tornado.ioloop
55
from tasks.task import TASKS
66
from tasks import task, apply_async
@@ -18,7 +18,7 @@ def t():
1818
def test_apply_async(self):
1919

2020
@task
21-
def t1(name, value, t):
21+
def t1(name, value):
2222
self.assertEqual(name == "hi", True)
2323
self.assertEqual(value == "word", True)
2424

@@ -29,10 +29,14 @@ def t2(t):
2929
def callback(_, msg):
3030
self.assertEqual(msg == b'OK', True)
3131

32-
loop = tornado.ioloop.IOLoop.current()
33-
threading.Thread(target=loop.start).start()
34-
time.sleep(9)
35-
apply_async(t1, callback=callback, args=("hi", "word", time.time()))
36-
apply_async(t2, callback=callback, delay=3000, args=(time.time(), ))
37-
time.sleep(9)
38-
loop.stop()
32+
def run_test_task():
33+
loop = tornado.ioloop.IOLoop.current()
34+
try:
35+
apply_async(t1, callback=callback, args=("hi", "word"))
36+
apply_async(t2, callback=callback, delay=3000, args=(time.time(),))
37+
finally:
38+
_loop.add_timeout(datetime.timedelta(seconds=9), loop.stop)
39+
40+
_loop = tornado.ioloop.IOLoop.current()
41+
_loop.add_timeout(datetime.timedelta(seconds=3), run_test_task)
42+
_loop.start()

0 commit comments

Comments
 (0)