-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathtest_pause.py
More file actions
75 lines (44 loc) · 1.59 KB
/
Copy pathtest_pause.py
File metadata and controls
75 lines (44 loc) · 1.59 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from mrq.job import Job
from mrq.queue import Queue, send_task
import time
def test_pause_resume(worker):
worker.start(flags="--paused_queues_refresh_interval=0.1")
Queue("high").pause()
assert Queue("high").is_paused()
# wait for the paused_queues list to be refreshed
time.sleep(2)
job_id1 = send_task(
"tests.tasks.general.MongoInsert", {"a": 41},
queue="high")
job_id2 = send_task(
"tests.tasks.general.MongoInsert", {"a": 43},
queue="low")
time.sleep(5)
job1 = Job(job_id1).fetch().data
job2 = Job(job_id2).fetch().data
assert job1["status"] == "queued"
assert job2["status"] == "success"
assert job2["result"] == {"a": 43}
assert worker.mongodb_jobs.tests_inserts.count() == 1
Queue("high").resume()
Job(job_id1).wait(poll_interval=0.01)
job1 = Job(job_id1).fetch().data
assert job1["status"] == "success"
assert job1["result"] == {"a": 41}
assert worker.mongodb_jobs.tests_inserts.count() == 2
worker.stop()
def test_pause_refresh_interval(worker):
""" Tests that a refresh interval of 0 disables the pause functionnality """
worker.start(flags="--paused_queues_refresh_interval=0")
Queue("high").pause()
assert Queue("high").is_paused()
# wait for the paused_queues list to be refreshed
time.sleep(2)
job_id1 = send_task(
"tests.tasks.general.MongoInsert", {"a": 41},
queue="high")
time.sleep(5)
job1 = Job(job_id1).fetch().data
assert job1["status"] == "success"
assert job1["result"] == {"a": 41}
worker.stop()