def test_attempt_count(broker, monkeypatch): monkeypatch.setattr(Conf, 'MAX_ATTEMPTS', 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
def test_attempt_count(broker, monkeypatch): monkeypatch.setattr(Conf, "MAX_ATTEMPTS", 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
def test_update_failed(broker): 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.success is False sleep(0.5) # second save - no success old_stopped = task['stopped'] task['stopped'] = timezone.now() save_task(task, broker) saved_task = Task.objects.get(id=task['id']) assert saved_task.stopped > old_stopped # third save - success task['stopped'] = timezone.now() task['result'] = 'result' task['success'] = True save_task(task, broker) saved_task = Task.objects.get(id=task['id']) assert saved_task.success is True # fourth save - no success task['result'] = None task['success'] = False task['stopped'] = old_stopped save_task(task, broker) # should not overwrite success saved_task = Task.objects.get(id=task['id']) assert saved_task.success is True assert saved_task.result == 'result'
def test_update_failed(broker): 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.success is False sleep(0.5) # second save - no success old_stopped = task["stopped"] task["stopped"] = timezone.now() save_task(task, broker) saved_task = Task.objects.get(id=task["id"]) assert saved_task.stopped > old_stopped # third save - success task["stopped"] = timezone.now() task["result"] = "result" task["success"] = True save_task(task, broker) saved_task = Task.objects.get(id=task["id"]) assert saved_task.success is True # fourth save - no success task["result"] = None task["success"] = False task["stopped"] = old_stopped save_task(task, broker) # should not overwrite success saved_task = Task.objects.get(id=task["id"]) assert saved_task.success is True assert saved_task.result == "result"
def test_update_failed(broker): 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.success is False sleep(0.5) # second save - no success old_stopped = task['stopped'] task['stopped']=timezone.now() save_task(task, broker) saved_task = Task.objects.get(id=task['id']) assert saved_task.stopped > old_stopped # third save - success task['stopped']=timezone.now() task['result']='result' task['success']=True save_task(task, broker) saved_task = Task.objects.get(id=task['id']) assert saved_task.success is True # fourth save - no success task['result'] = None task['success'] = False task['stopped'] = old_stopped save_task(task, broker) # should not overwrite success saved_task = Task.objects.get(id=task['id']) assert saved_task.success is True assert saved_task.result == 'result'