Skip to content

Commit

Permalink
Remove explicit timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasz-grz committed Feb 12, 2025
1 parent e2980ee commit 36bd540
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 3 additions & 0 deletions nat-lab/tests/telio.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ async def notify_peer_state(
await asyncio.sleep(0.1)

async def notify_link_state(self, public_key: str, states: List[LinkState]) -> None:
"""Busy wait until the last link_state event matches one of the `states` for `public_key`."""
while True:
peer = self.get_peer_info(public_key)
if peer and peer.link_state in states:
Expand Down Expand Up @@ -276,6 +277,7 @@ async def wait_for_link_state(
state: List[LinkState],
timeout: Optional[float] = None,
) -> None:
"""Wait until the last link_state event matches one of the `states` for `public_key`."""
await asyncio.wait_for(
self._runtime.notify_link_state(public_key, state), timeout
)
Expand Down Expand Up @@ -573,6 +575,7 @@ async def wait_for_link_state(
states: List[LinkState],
timeout: Optional[float] = None,
) -> None:
"""Wait until the last link_state event matches one of the `states` for `public_key`."""
await self.get_events().wait_for_link_state(
public_key,
states,
Expand Down
13 changes: 7 additions & 6 deletions nat-lab/tests/test_events_link_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ async def test_event_link_state_peers_exchanging_data_for_a_long_time(
await asyncio.sleep(1)
await ping(connection_alpha, beta.ip_addresses[0])
await ping(connection_beta, alpha.ip_addresses[0])
await client_alpha.wait_for_link_state(beta.public_key, [LinkState.UP], 1)
await client_beta.wait_for_link_state(alpha.public_key, [LinkState.UP], 1)
await client_alpha.wait_for_link_state(beta.public_key, [LinkState.UP])
await client_beta.wait_for_link_state(alpha.public_key, [LinkState.UP])


@pytest.mark.asyncio
Expand Down Expand Up @@ -260,8 +260,8 @@ async def test_event_link_state_peers_exchanging_data_then_idling_then_resume(
)

# Expect the links are still UP
await client_alpha.wait_for_link_state(beta.public_key, [LinkState.UP], 1)
await client_beta.wait_for_link_state(alpha.public_key, [LinkState.UP], 1)
await client_alpha.wait_for_link_state(beta.public_key, [LinkState.UP])
await client_beta.wait_for_link_state(alpha.public_key, [LinkState.UP])


@pytest.mark.asyncio
Expand All @@ -288,6 +288,7 @@ async def test_event_link_state_peer_goes_offline(
with pytest.raises(asyncio.TimeoutError):
await ping(connection_alpha, beta.ip_addresses[0], 3)

# Expect the link to still be UP for the fist 10 seconds
with pytest.raises(asyncio.TimeoutError):
await client_alpha.wait_for_link_state(
beta.public_key, [LinkState.DOWN], 10
Expand All @@ -296,9 +297,9 @@ async def test_event_link_state_peer_goes_offline(
# Expect the link down event
# It should arrive in 11-15 seconds after the link is cut and ping mod disabled
# And 22-25 seconds if the ping mod is enabled
await client_alpha.wait_for_link_state(beta.public_key, [LinkState.DOWN], 30)
await client_alpha.wait_for_link_state(beta.public_key, [LinkState.DOWN])
# Although the beta device has been stopped, it should still see alpha as up
await client_beta.wait_for_link_state(alpha.public_key, [LinkState.UP], 5)
await client_beta.wait_for_link_state(alpha.public_key, [LinkState.UP])


@pytest.mark.asyncio
Expand Down

0 comments on commit 36bd540

Please sign in to comment.