mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-07 01:38:11 +08:00
adds tests
This commit is contained in:
@@ -21,7 +21,8 @@ def test_admin_views(admin_client, monkeypatch):
|
|||||||
func='test.fail',
|
func='test.fail',
|
||||||
started=timezone.now(),
|
started=timezone.now(),
|
||||||
stopped=timezone.now(),
|
stopped=timezone.now(),
|
||||||
success=False)
|
success=False,
|
||||||
|
attempt_count=1)
|
||||||
tag = uuid()
|
tag = uuid()
|
||||||
t = Task.objects.create(
|
t = Task.objects.create(
|
||||||
id=tag[1],
|
id=tag[1],
|
||||||
@@ -29,7 +30,8 @@ def test_admin_views(admin_client, monkeypatch):
|
|||||||
func='test.success',
|
func='test.success',
|
||||||
started=timezone.now(),
|
started=timezone.now(),
|
||||||
stopped=timezone.now(),
|
stopped=timezone.now(),
|
||||||
success=True)
|
success=True,
|
||||||
|
attempt_count=1)
|
||||||
q = OrmQ.objects.create(
|
q = OrmQ.objects.create(
|
||||||
key='test',
|
key='test',
|
||||||
payload=SignedPackage.dumps({'id': 1, 'func': 'test', 'name': 'test'}))
|
payload=SignedPackage.dumps({'id': 1, 'func': 'test', 'name': 'test'}))
|
||||||
|
|||||||
@@ -397,6 +397,41 @@ def test_bad_secret(broker, monkeypatch):
|
|||||||
broker.delete_queue()
|
broker.delete_queue()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_attempt_count(broker, monkeypatch):
|
||||||
|
monkeypatch.setattr(Conf, 'ATTEMPT_COUNT', 3)
|
||||||
|
tag = uuid()
|
||||||
|
task = {'id': tag[1],
|
||||||
|
'name': tag[0],
|
||||||
|
'func': 'math.copysign',
|
||||||
|
'args': (1, -1),
|
||||||
|
'kwargs': {},
|
||||||
|
'started': timezone.now(),
|
||||||
|
'stopped': timezone.now(),
|
||||||
|
'success': False,
|
||||||
|
'result': None}
|
||||||
|
# initial save - no success
|
||||||
|
save_task(task, broker)
|
||||||
|
assert Task.objects.filter(id=task['id']).exists()
|
||||||
|
saved_task = Task.objects.get(id=task['id'])
|
||||||
|
assert saved_task.attempt_count == 1
|
||||||
|
sleep(0.5)
|
||||||
|
# second save
|
||||||
|
old_stopped = task['stopped']
|
||||||
|
task['stopped'] = timezone.now()
|
||||||
|
save_task(task, broker)
|
||||||
|
saved_task = Task.objects.get(id=task['id'])
|
||||||
|
assert saved_task.attempt_count == 2
|
||||||
|
# third save -
|
||||||
|
task['stopped'] = timezone.now()
|
||||||
|
save_task(task, broker)
|
||||||
|
saved_task = Task.objects.get(id=task['id'])
|
||||||
|
assert saved_task.attempt_count == 3
|
||||||
|
# task should be removed from queue
|
||||||
|
assert broker.queue_size() == 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_update_failed(broker):
|
def test_update_failed(broker):
|
||||||
tag = uuid()
|
tag = uuid()
|
||||||
|
|||||||
Reference in New Issue
Block a user