diff --git a/flamenco_worker/upstream_update_queue.py b/flamenco_worker/upstream_update_queue.py index cda9e61effaa0e7352781700eb953b930432192d..65cca0bf69bd3d2320b13265de84ed532446e7ef 100644 --- a/flamenco_worker/upstream_update_queue.py +++ b/flamenco_worker/upstream_update_queue.py @@ -139,7 +139,7 @@ class TaskUpdateQueue: # The task was assigned to another worker, so we're not allowed to # push updates for it. We have to un-queue this update, as it will # never be accepted. - self._log.warning('Task was assigned to another worker, discarding update.') + self._log.warning('discarding update, Manager says %s', resp.text) else: resp.raise_for_status() self._log.debug('Master accepted pushed update.') diff --git a/tests/mock_responses.py b/tests/mock_responses.py index 9d2d534e37e6e2220a5ca14c0723300899f452e6..e8bb6b2e1bb1829e34633b2fe5e8ce0617d58263 100644 --- a/tests/mock_responses.py +++ b/tests/mock_responses.py @@ -23,6 +23,24 @@ class JsonResponse: raise requests.HTTPError(self.status_code) +@attr.s +class TextResponse: + """Mocked HTTP response returning text. + + Maybe we want to switch to using unittest.mock.Mock for this, + or to using the responses package. + """ + + text = attr.ib(default='', validator=attr.validators.instance_of(str)) + status_code = attr.ib(default=200, validator=attr.validators.instance_of(int)) + + def raise_for_status(self): + if 200 <= self.status_code < 300: + return + + raise requests.HTTPError(self.status_code) + + @attr.s class EmptyResponse: """Mocked HTTP response returning an empty 204. diff --git a/tests/test_upstream_update_queue.py b/tests/test_upstream_update_queue.py index 4f8083a68bd16f7a1212ef89a002da246df4767a..85a4d65b45450e3c5e23f72bae496ed2460d9aa2 100644 --- a/tests/test_upstream_update_queue.py +++ b/tests/test_upstream_update_queue.py @@ -152,7 +152,7 @@ class TaskUpdateQueueTest(AbstractWorkerTest): """A 409 Conflict response should discard a queued task update. """ - from mock_responses import JsonResponse, EmptyResponse + from mock_responses import TextResponse # Try different value types payload = {'key': 'value', @@ -165,7 +165,7 @@ class TaskUpdateQueueTest(AbstractWorkerTest): nonlocal tries tries += 1 self.shutdown_future.cancel() - return JsonResponse({}, status_code=409) + return TextResponse("no", status_code=409) self.manager.post.side_effect = push_callback