mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-03 11:18:11 +08:00
Add unit test for sync=True change.
When sync=True, re-raise exceptions from the worker.
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
|
|
||||||
|
class TaskError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def countdown(n):
|
def countdown(n):
|
||||||
while n > 0:
|
while n > 0:
|
||||||
n -= 1
|
n -= 1
|
||||||
@@ -44,3 +48,7 @@ def hello():
|
|||||||
|
|
||||||
def result(obj):
|
def result(obj):
|
||||||
print(f"RESULT HOOK {obj.name} : {obj.result()}")
|
print(f"RESULT HOOK {obj.name} : {obj.result()}")
|
||||||
|
|
||||||
|
|
||||||
|
def raise_exception():
|
||||||
|
raise TaskError("this is an exception!")
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from django_q.models import Task, Success
|
|||||||
from django_q.conf import Conf
|
from django_q.conf import Conf
|
||||||
from django_q.status import Stat
|
from django_q.status import Stat
|
||||||
from django_q.brokers import get_broker, Broker
|
from django_q.brokers import get_broker, Broker
|
||||||
from django_q.tests.tasks import multiply
|
from django_q.tests.tasks import multiply, TaskError
|
||||||
from django_q.queues import Queue
|
from django_q.queues import Queue
|
||||||
|
|
||||||
|
|
||||||
@@ -45,6 +45,11 @@ def test_sync(broker):
|
|||||||
task = async_task('django_q.tests.tasks.count_letters', DEFAULT_WORDLIST, broker=broker, sync=True)
|
task = async_task('django_q.tests.tasks.count_letters', DEFAULT_WORDLIST, broker=broker, sync=True)
|
||||||
assert result(task) == 1506
|
assert result(task) == 1506
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_sync_raise_exception(broker):
|
||||||
|
with pytest.raises(TaskError):
|
||||||
|
async_task('django_q.tests.tasks.raise_exception', broker=broker, sync=True)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_cluster_initial(broker):
|
def test_cluster_initial(broker):
|
||||||
|
|||||||
Reference in New Issue
Block a user