mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-06 21:28:12 +08:00
Adds timeout and reincarnation test
Also found a bug because of this.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import sys
|
||||
import os
|
||||
from multiprocessing import Queue, Event, Value
|
||||
import threading
|
||||
from time import sleep
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -181,6 +183,20 @@ def test_async(r):
|
||||
assert result(h) == 12
|
||||
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
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def assert_result(task):
|
||||
|
||||
Reference in New Issue
Block a user