Skip to content

Commit

Permalink
test: fix exception on libp2p_mailbox test
Browse files Browse the repository at this point in the history
  • Loading branch information
0xArdi committed Nov 14, 2024
1 parent 937c0c1 commit 46ff747
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/package_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
| connection/valory/p2p_libp2p_mailbox/0.1.0 | `bafybeiecclc65ogngs3piaxpwhiyl77mlpqun5ejlyv4kamwzrrh746guq` |
| connection/fetchai/local/0.20.0 | `bafybeiema4rnxi54luhzbrccb27pfrwlohemka45eqf4nidgmtkwwmxeyi` |
| connection/valory/http_client/0.23.0 | `bafybeihi772xgzpqeipp3fhmvpct4y6e6tpjp4sogwqrnf3wqspgeilg4u` |
| connection/valory/test_libp2p/0.1.0 | `bafybeial7uzniyiuwpe4h2emzipaheuqzpsyr5hnwthpk7m4rb267wzwpa` |
| connection/valory/test_libp2p/0.1.0 | `bafybeigoeurcepbax7jju6def3ebshctelivsc7fwjevnwpi2hlmqxxn3u` |
| skill/fetchai/echo/0.19.0 | `bafybeicoawiackcbgqo3na3e56tpdc62atag4yxknur77py37caqq4mmya` |
| skill/fetchai/error_test_skill/0.1.0 | `bafybeihsbtlpe7h6fsvoxban5rilkmwviwkokul5cqym6atoolirontiyu` |
| skill/fetchai/gym/0.20.0 | `bafybeie7y2fsxfuhsqxqcaluo5exskmrm5q3a6e2hfcskcuvzvxjjhijh4` |
Expand Down
2 changes: 1 addition & 1 deletion packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"connection/valory/p2p_libp2p_mailbox/0.1.0": "bafybeiecclc65ogngs3piaxpwhiyl77mlpqun5ejlyv4kamwzrrh746guq",
"connection/fetchai/local/0.20.0": "bafybeiema4rnxi54luhzbrccb27pfrwlohemka45eqf4nidgmtkwwmxeyi",
"connection/valory/http_client/0.23.0": "bafybeihi772xgzpqeipp3fhmvpct4y6e6tpjp4sogwqrnf3wqspgeilg4u",
"connection/valory/test_libp2p/0.1.0": "bafybeiefuha46oyekz255vjq2szjxv563hfjiner44v7u3g55yatuqzcly",
"connection/valory/test_libp2p/0.1.0": "bafybeigoeurcepbax7jju6def3ebshctelivsc7fwjevnwpi2hlmqxxn3u",
"skill/fetchai/echo/0.19.0": "bafybeicoawiackcbgqo3na3e56tpdc62atag4yxknur77py37caqq4mmya",
"skill/fetchai/error_test_skill/0.1.0": "bafybeihsbtlpe7h6fsvoxban5rilkmwviwkokul5cqym6atoolirontiyu",
"skill/fetchai/gym/0.20.0": "bafybeie7y2fsxfuhsqxqcaluo5exskmrm5q3a6e2hfcskcuvzvxjjhijh4",
Expand Down
4 changes: 2 additions & 2 deletions packages/valory/connections/test_libp2p/connection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ fingerprint:
tests/test_p2p_libp2p_client/__init__.py: bafybeihjzl7ireo5rbnxcdbghbncykgcgcbh26m4mjjofsseeflauuf6sy
tests/test_p2p_libp2p_client/test_aea_cli.py: bafybeie5yaezltj4xydnqghltt7f2t4vicdts5rm6bz4fdpt4kkkd42cyu
tests/test_p2p_libp2p_client/test_communication.py: bafybeiceec5zsd2u37t56oiajijgwx7frpo3wzu4qdfd3lcq3lcldyqszq
tests/test_p2p_libp2p_client/test_errors.py: bafybeidk7g4tucudqfafwgio7hpdgsz4gexh5lwvdrnpttnd6lt3ak4t7u
tests/test_p2p_libp2p_client/test_errors.py: bafybeihopjaixftexdru35rxf75tr45itr6ygoao2ajxax3jvq6mcopw6m
tests/test_p2p_libp2p_mailbox/__init__.py: bafybeiad64wftnugaahubhqc6bcqzg7om4435dzojdv7oeq4zdmn7kxzui
tests/test_p2p_libp2p_mailbox/test_aea_cli.py: bafybeievjaiacpvcpabemtrmmeejbf4cbkrqzhu2ekxzyfyeg42ityxn5q
tests/test_p2p_libp2p_mailbox/test_communication.py: bafybeiaiwlqxuzp34nu33s5pz6sudvwmdi3h2ckfa4mmwyvd6wqn2elo4m
tests/test_p2p_libp2p_mailbox/test_errors.py: bafybeiampgm6dxpo4tqiyhyhpwr5d3kdsq5x5vwl323oauhdzmsnprf4bi
tests/test_p2p_libp2p_mailbox/test_errors.py: bafybeie2t3zjjjjbyfd3lno2f6p4fa6jdttq2gluwfe5mmny5g6r5zp2oi
tests/test_p2p_libp2p_mailbox/test_mailbox_service.py: bafybeibp3bkwkrw57qahvuysjdlumywtlk3te5gsvusgrvhsc75k7rrk4u
fingerprint_ignore_patterns: []
connections:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ async def test_reconnect_on_send_fail(self):
) as connect_mock, patch.object(
self.connection, "_ensure_valid_envelope_for_external_comms"
):
with pytest.raises(Exception, match="oops"):
await self.connection._send_envelope_with_node_client(Mock())
connect_mock.assert_called()
await self.connection._send_envelope_with_node_client(Mock())
connect_mock.assert_called()


@pytest.mark.asyncio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
# ------------------------------------------------------------------------------

"""This test module contains negative tests for Libp2p tcp client connection."""

# pylint: skip-file
from unittest.mock import Mock, patch

import pytest

Expand All @@ -31,6 +30,9 @@
BaseP2PLibp2pTest,
_make_libp2p_mailbox_connection,
)
from packages.valory.connections.test_libp2p.tests.test_p2p_libp2p_client.test_errors import (
DONE_FUTURE,
)
from packages.valory.connections.test_libp2p.tests.test_p2p_libp2p_client.test_errors import (
TestLibp2pClientConnectionFailureConnectionSetup as BaseFailureConnectionSetup,
)
Expand All @@ -39,6 +41,9 @@
)


# pylint: skip-file


@pytest.mark.asyncio
class TestLibp2pMailboxConnectionFailureNodeNotConnected(BaseFailureNodeNotConnected):
"""Test that connection fails when node not running"""
Expand All @@ -48,6 +53,21 @@ class TestLibp2pMailboxConnectionFailureNodeNotConnected(BaseFailureNodeNotConne
# overwrite, no mailbox equivalent of P2PLibp2pClientConnection (TCPSocketChannelClient)
test_connect_attempts = None

@pytest.mark.asyncio
async def test_reconnect_on_send_fail(self):
"""Test reconnect on send fails."""

self.connection._node_client = Mock()
self.connection._node_client.send_envelope.side_effect = Exception("oops")
with patch.object(
self.connection, "_perform_connection_to_node", return_value=DONE_FUTURE
) as connect_mock, patch.object(
self.connection, "_ensure_valid_envelope_for_external_comms"
):
with pytest.raises(Exception, match="oops"):
await self.connection._send_envelope_with_node_client(Mock())
connect_mock.assert_called()


class TestLibp2pMailboxConnectionFailureConnectionSetup(BaseFailureConnectionSetup):
"""Test that connection fails when setup incorrectly"""
Expand Down

0 comments on commit 46ff747

Please sign in to comment.