From 1c16cf37c4cc8c0fd45ace9fd680106d69273880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= <sybren@stuvel.eu> Date: Fri, 29 Sep 2017 14:41:07 +0200 Subject: [PATCH] Include response text when Manager refuses task update. This refusal can be because another worker is working on the task, but can also be for other reasons (like the task no longer being runnable). --- flamenco_worker/upstream_update_queue.py | 2 +- tests/mock_responses.py | 18 ++++++++++++++++++ tests/test_upstream_update_queue.py | 4 ++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/flamenco_worker/upstream_update_queue.py b/flamenco_worker/upstream_update_queue.py index cda9e61e..65cca0bf 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 9d2d534e..e8bb6b2e 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 4f8083a6..85a4d65b 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 -- GitLab