mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-08 05:48:11 +08:00
Merge pull request #18 from Koed00/dev
Adds a `timeout` override per task
This commit is contained in:
@@ -213,6 +213,60 @@ def test_timeout(r):
|
||||
assert start_event.is_set()
|
||||
assert s.status() == Conf.STOPPED
|
||||
assert s.reincarnations == 1
|
||||
r.delete(list_key)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_timeout(r):
|
||||
# set up the Sentinel
|
||||
list_key = 'timeout_test:q'
|
||||
async('django_q.tests.tasks.count_forever', list_key=list_key)
|
||||
start_event = Event()
|
||||
stop_event = Event()
|
||||
# Set a timer to stop the Sentinel
|
||||
threading.Timer(3, stop_event.set).start()
|
||||
s = Sentinel(stop_event, start_event, list_key=list_key, timeout=1)
|
||||
assert start_event.is_set()
|
||||
assert s.status() == Conf.STOPPED
|
||||
assert s.reincarnations == 1
|
||||
r.delete(list_key)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_timeout_override(r):
|
||||
# set up the Sentinel
|
||||
list_key = 'timeout_override_test:q'
|
||||
async('django_q.tests.tasks.count_forever', list_key=list_key, timeout=1)
|
||||
start_event = Event()
|
||||
stop_event = Event()
|
||||
# Set a timer to stop the Sentinel
|
||||
threading.Timer(3, stop_event.set).start()
|
||||
s = Sentinel(stop_event, start_event, list_key=list_key, timeout=10)
|
||||
assert start_event.is_set()
|
||||
assert s.status() == Conf.STOPPED
|
||||
assert s.reincarnations == 1
|
||||
r.delete(list_key)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_recycle(r):
|
||||
# set up the Sentinel
|
||||
list_key = 'test_recycle_test:q'
|
||||
async('django_q.tests.tasks.multiply', 2, 2, list_key=list_key)
|
||||
async('django_q.tests.tasks.multiply', 2, 2, list_key=list_key)
|
||||
async('django_q.tests.tasks.multiply', 2, 2, list_key=list_key)
|
||||
start_event = Event()
|
||||
stop_event = Event()
|
||||
# override settings
|
||||
Conf.RECYCLE = 2
|
||||
Conf.WORKERS = 1
|
||||
# Set a timer to stop the Sentinel
|
||||
threading.Timer(3, stop_event.set).start()
|
||||
s = Sentinel(stop_event, start_event, list_key=list_key)
|
||||
assert start_event.is_set()
|
||||
assert s.status() == Conf.STOPPED
|
||||
assert s.reincarnations == 1
|
||||
r.delete(list_key)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
||||
Reference in New Issue
Block a user