Adds timeout and reincarnation test

Also found a bug because of this.
This commit is contained in:
Ilan Steemers
2015-07-02 12:10:18 +02:00
parent a9a9d8ec34
commit 5399865f4e
3 changed files with 32 additions and 6 deletions
+8
View File
@@ -1,4 +1,7 @@
# simple countdown, returns nothing
from time import sleep
def countdown(n):
while n > 0:
n -= 1
@@ -23,6 +26,11 @@ def word_multiply(x, word=''):
return len(word) * x
def count_forever():
while True:
sleep(0.5)
def get_task_name(task):
return task.name
+16
View File
@@ -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):