Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5080 from golemfactory/dev-provide-reason
Browse files Browse the repository at this point in the history
Report CannotTakeWork instead of None
  • Loading branch information
jiivan authored Jan 30, 2020
2 parents 5550f5b + 37ac54c commit 0cc0980
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion golem/task/tasksession.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ def _react_to_task_to_compute(self, msg: message.tasks.TaskToCompute):
)

def _cannot_compute(reason):
assert isinstance(reason, message.tasks.CannotComputeTask.REASON)
logger.info(
"Cannot compute subtask. subtask_id: %r, reason: %r",
ctd["subtask_id"],
Expand Down Expand Up @@ -698,7 +699,7 @@ def _cannot_compute(reason):
return

if not self.task_server.task_given(msg):
_cannot_compute(None)
_cannot_compute(reasons.CannotTakeWork)
return

# pylint: enable=too-many-return-statements, too-many-branches
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ eventlet==0.24.1
fasteners==0.15
flatbuffers==1.11
fs==2.4.4
Golem-Messages==3.14.1
Golem-Messages==3.15.0
Golem-Smart-Contracts-Interface==1.11.1
Golem-Task-Api==0.24.1
greenlet==0.4.15
Expand Down
2 changes: 1 addition & 1 deletion requirements_to-freeze.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ docker==3.5.0
enforce==0.3.4
eth-utils==1.0.3
ethereum==1.6.1
Golem-Messages==3.14.1
Golem-Messages==3.15.0
Golem-Smart-Contracts-Interface==1.11.1
Golem-Task-Api==0.24.1
html2text==2018.1.9
Expand Down
11 changes: 11 additions & 0 deletions tests/golem/task/test_tasksession.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,17 @@ def test_react_to_task_to_compute(self):
self.task_session.task_server.task_given.assert_called_with(ttc)
self.conn.close.assert_not_called()

def test_react_to_task_to_compute_task_not_give(self):
self.task_session.task_server.task_given.return_value = False
ctd = self.ctd()
ttc: message.tasks.TaskToCompute = self.ttc_prepare_and_react(ctd)
self.task_session.send.assert_called_once_with(
message.tasks.CannotComputeTask(
task_to_compute=ttc,
reason=message.tasks.CannotComputeTask.REASON.CannotTakeWork,
),
)

def test_no_ctd(self, *_):
# ComputeTaskDef is None -> failure
self.ttc_prepare_and_react(None)
Expand Down

0 comments on commit 0cc0980

Please sign in to comment.