Skip to content

Commit a490347

Browse files
committed
Add a test for scheduler restart
1 parent 55e8310 commit a490347

1 file changed

Lines changed: 25 additions & 7 deletions

File tree

tests/test_scheduler.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,20 @@ def test_scheduler_simple(worker, p_flags):
6767
@pytest.mark.parametrize(["p_flags"], PROCESS_CONFIGS)
6868
def test_scheduler_dailytime(worker, p_flags):
6969

70+
now = time.time()
71+
7072
# Task is scheduled in 3 seconds
71-
worker.start(
72-
flags="--scheduler --config tests/fixtures/config-scheduler3.py %s" % p_flags,
73-
env={
74-
# We need to pass this in the environment so that each worker has the
75-
# exact same hash
76-
"MRQ_TEST_SCHEDULER_TIME": str(time.time() + 10)
77-
})
73+
def _start(deps=True):
74+
worker.start(
75+
flags="--scheduler --config tests/fixtures/config-scheduler3.py %s" % p_flags,
76+
deps=deps,
77+
env={
78+
# We need to pass this in the environment so that each worker has the
79+
# exact same hash
80+
"MRQ_TEST_SCHEDULER_TIME": str(now + 10)
81+
})
82+
83+
_start(deps=True)
7884

7985
collection = worker.mongodb_jobs.tests_inserts
8086

@@ -95,6 +101,18 @@ def test_scheduler_dailytime(worker, p_flags):
95101
assert collection.find().count() == 2
96102
assert collection.find({"params.b": "test"}).count() == 1
97103

104+
# .. even if we restart
105+
worker.stop(deps=False)
106+
107+
time.sleep(1)
108+
109+
_start(deps=False)
110+
111+
time.sleep(5)
112+
113+
assert collection.find().count() == 2
114+
assert collection.find({"params.b": "test"}).count() == 1
115+
98116

99117
def test_scheduler_weekday_dailytime(worker):
100118
# Task is scheduled in 5 seconds

0 commit comments

Comments
 (0)