From 62f5201a38fd62bddea656680f8e51379d310242 Mon Sep 17 00:00:00 2001 From: Derek Arnold Date: Sun, 15 Sep 2024 12:04:22 -0500 Subject: [PATCH] Add test covering retry logic --- meshtastic/tests/test_mesh_interface.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/meshtastic/tests/test_mesh_interface.py b/meshtastic/tests/test_mesh_interface.py index cace7eb..bacf85c 100644 --- a/meshtastic/tests/test_mesh_interface.py +++ b/meshtastic/tests/test_mesh_interface.py @@ -176,6 +176,22 @@ def test_getNode_not_local_timeout(capsys): assert re.match(r"Timed out trying to retrieve channel info, retrying", out) assert err == "" +@pytest.mark.unit +@pytest.mark.usefixtures("reset_mt_config") +def test_getNode_not_local_timeout_attempts(capsys): + """Test getNode not local, simulate timeout""" + iface = MeshInterface(noProto=True) + anode = MagicMock(autospec=Node) + anode.waitForConfig.return_value = False + with patch("meshtastic.node.Node", return_value=anode): + with pytest.raises(SystemExit) as pytest_wrapped_e: + iface.getNode("bar2", requestChannelAttempts=2) + assert pytest_wrapped_e.type == SystemExit + assert pytest_wrapped_e.value.code == 1 + out, err = capsys.readouterr() + assert out == 'Timed out trying to retrieve channel info, retrying\nError: Timed out waiting for channels, giving up\n' + assert err == "" + @pytest.mark.unit @pytest.mark.usefixtures("reset_mt_config")