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

treat retrieval of an incompatible message from history as a "message… #4305

Merged
merged 4 commits into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion golem/network/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ def get_sync_as_message(cls, *args, **kwargs) -> message.base.Message:
if not db_result:
raise MessageNotFound()
db_msg = db_result[0]
return db_msg.as_message()
try:
return db_msg.as_message()
except AttributeError:
# in case an incompatible message from an earlier version of
# golem-messages is retrieved, just treat it the same
# as if the message was not found
raise MessageNotFound()

def add(self, msg_dict: dict) -> None:
"""
Expand Down
42 changes: 41 additions & 1 deletion tests/golem/network/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def message_count():
return NetworkMessage.select().count()


class TestMessageHistoryService(DatabaseFixture):
class MessageHistoryServiceTestBase(DatabaseFixture):

def setUp(self):
super().setUp()
Expand All @@ -32,6 +32,8 @@ def tearDown(self):
super().tearDown()
history.MessageHistoryService.instance = None


class TestMessageHistoryService(MessageHistoryServiceTestBase):
@staticmethod
def _build_dict(task=None, subtask=None):
return dict(
Expand Down Expand Up @@ -256,6 +258,44 @@ def test_loop_remove_sync(self):
assert not self.service.remove_sync.called


class TestMessageHistoryGet(MessageHistoryServiceTestBase):
def setUp(self):
super().setUp()
self.msg = msg_factories.tasks.TaskToComputeFactory()
self.msg._fake_sign()
self.node_id = fake.binary(length=64)
self.local_role = fake.random_element(Actor)
self.remote_role = fake.random_element(Actor)

history.add(
msg=self.msg,
node_id=self.node_id,
local_role=self.local_role,
remote_role=self.remote_role,
sync=True
)

def test_get(self):
msg_retrieved = history.get(
'TaskToCompute',
subtask_id=self.msg.subtask_id,
node_id=self.node_id,
)

self.assertEqual(self.msg, msg_retrieved)

def test_get_pickle_fail(self):
with mock.patch('golem.model.pickle.loads',
mock.Mock(side_effect=AttributeError)):
msg_retrieved = history.get(
'TaskToCompute',
subtask_id=self.msg.subtask_id,
node_id=self.node_id,
)

self.assertIsNone(msg_retrieved)


@mock.patch("golem.network.history.MessageHistoryService.add")
class TestAdd(unittest.TestCase):
def setUp(self):
Expand Down