Skip to content
Snippets Groups Projects
Commit 1c16cf37 authored by Sybren A. Stüvel's avatar Sybren A. Stüvel
Browse files

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).
parent c15ef584
Branches
Tags
No related merge requests found
...@@ -139,7 +139,7 @@ class TaskUpdateQueue: ...@@ -139,7 +139,7 @@ class TaskUpdateQueue:
# The task was assigned to another worker, so we're not allowed to # 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 # push updates for it. We have to un-queue this update, as it will
# never be accepted. # 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: else:
resp.raise_for_status() resp.raise_for_status()
self._log.debug('Master accepted pushed update.') self._log.debug('Master accepted pushed update.')
......
...@@ -23,6 +23,24 @@ class JsonResponse: ...@@ -23,6 +23,24 @@ class JsonResponse:
raise requests.HTTPError(self.status_code) 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 @attr.s
class EmptyResponse: class EmptyResponse:
"""Mocked HTTP response returning an empty 204. """Mocked HTTP response returning an empty 204.
......
...@@ -152,7 +152,7 @@ class TaskUpdateQueueTest(AbstractWorkerTest): ...@@ -152,7 +152,7 @@ class TaskUpdateQueueTest(AbstractWorkerTest):
"""A 409 Conflict response should discard a queued task update. """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 # Try different value types
payload = {'key': 'value', payload = {'key': 'value',
...@@ -165,7 +165,7 @@ class TaskUpdateQueueTest(AbstractWorkerTest): ...@@ -165,7 +165,7 @@ class TaskUpdateQueueTest(AbstractWorkerTest):
nonlocal tries nonlocal tries
tries += 1 tries += 1
self.shutdown_future.cancel() self.shutdown_future.cancel()
return JsonResponse({}, status_code=409) return TextResponse("no", status_code=409)
self.manager.post.side_effect = push_callback self.manager.post.side_effect = push_callback
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment