Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLT-5683: Increase constrains in link state testcases #909

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dfetti
Copy link
Contributor

@dfetti dfetti commented Oct 29, 2024

Previously the link state testcase scenarios were structured like setup, do some interaction between peers, sleep for a while and check the reported link states. This approach did not consider the timings of the events.

Proposed solution consists in checking the state constantly during the scenario, not only at the end of it.

☑️ Definition of Done checklist

  • Commit history is clean (requirements)
  • README.md is updated
  • Functionality is covered by unit or integration tests

@dfetti dfetti requested a review from a team as a code owner October 29, 2024 07:53
@dfetti dfetti force-pushed the LLT-5683-increase-constranins-in-link-state-testcases branch from e02a96d to 4b5ef12 Compare October 29, 2024 07:54
@dfetti dfetti force-pushed the LLT-5683-increase-constranins-in-link-state-testcases branch from 4b5ef12 to c1193b5 Compare December 18, 2024 07:55
@dfetti dfetti force-pushed the LLT-5683-increase-constranins-in-link-state-testcases branch from c1193b5 to e93f34c Compare January 6, 2025 10:54
@dfetti dfetti force-pushed the LLT-5683-increase-constranins-in-link-state-testcases branch from e93f34c to 0ab9458 Compare January 6, 2025 10:55
@dfetti dfetti force-pushed the LLT-5683-increase-constranins-in-link-state-testcases branch from 0ab9458 to 8aaa4d9 Compare January 6, 2025 16:18
Previously the link state testcase scenarios were structured like setup,
do some interaction between peers, sleep for a while and check the reported link states.
This approach did not consider the timings of the events.

Proposed solution consists in checking the state constantly during the
scenario, not only at the end of it.

Signed-off-by: Daniel Fetti <[email protected]>
@LukasPukenis LukasPukenis force-pushed the LLT-5683-increase-constranins-in-link-state-testcases branch from 8aaa4d9 to e2980ee Compare February 7, 2025 09:21
@tomasz-grz tomasz-grz self-assigned this Feb 12, 2025
async def notify_link_state(self, public_key: str, states: List[LinkState]) -> None:
while True:
peer = self.get_peer_info(public_key)
if peer and peer.link_state in states:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this return for any first matching state?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_peer_info only returns the last event. So this waits until the last event is the specified states. Not sure why it's a List though, to match multiple event types?

)
),
],
timeout=25,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting that pytest.raises(asyncio.TimeoutError) are good to be left with an explicit timeout value. On Windows which is producing delays this is still gonna pass and on containers that have no delays it will assert for correctness(things don't happen earlier than expected)

# 1 down event when Connecting, 1 up event when Connected
assert alpha_events == [LinkState.DOWN, LinkState.UP]
assert beta_events == [LinkState.DOWN, LinkState.UP]
await client_alpha.wait_for_link_state(beta.public_key, [LinkState.UP], 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just putting in writing what we already talked about wait_for_link_state should have no explicit timeout set or else it will flake on Windows test runners :/

assert beta_events == [LinkState.DOWN, LinkState.UP, LinkState.DOWN]
# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am mentioning for general context and also because these comments are a bit ambiguous since the values are not exact but rather ranges which might be confusing now looking at it :)

Link detection is based on 10seconds which is a guarantee from WireGuard(passive-keepalive) and additional configurable RTT - see _generate_setup_parameter_pair() which now is 1 so 11 second in total.

If enhanched detection is used then icmp echo aka ping is also used additionally before reporting the state which adds some extra time(forgot how much).

@tomasz-grz tomasz-grz changed the title Increase constrains in link state testcases LLT-5683: Increase constrains in link state testcases Feb 12, 2025
async def notify_link_state(self, public_key: str, states: List[LinkState]) -> None:
while True:
peer = self.get_peer_info(public_key)
if peer and peer.link_state in states:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_peer_info only returns the last event. So this waits until the last event is the specified states. Not sure why it's a List though, to match multiple event types?


await asyncio.sleep(25)
alpha_events = client_beta.get_link_state_events(alpha.public_key)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we would still want to call get_link_state_events() right after notify_link_state() just to make sure we have the correct sequence of events [LinkState.DOWN, LinkState.UP, LinkState.DOWN]?

beta_events = client_alpha.get_link_state_events(beta.public_key)

# The connection is normal and events should be: initial down, then several up events but no more down events
assert alpha_events.count(LinkState.DOWN) == 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I think checking the count in tests is really good practice

@tomasz-grz tomasz-grz force-pushed the LLT-5683-increase-constranins-in-link-state-testcases branch from 35337a7 to 1051cc3 Compare February 12, 2025 15:14
`notify_link_state()` method is doing a busy loop. Instead we can use
synchronization primitives to make the code event driven and remove
unnecessary sleep.
@tomasz-grz tomasz-grz force-pushed the LLT-5683-increase-constranins-in-link-state-testcases branch from 1051cc3 to 7c1d372 Compare February 12, 2025 15:25
[
asyncio.create_task(
client_alpha.wait_for_new_link_state(
beta.public_key, [LinkState.DOWN]
Copy link
Contributor

@tomasz-grz tomasz-grz Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess technically we should check for [LinkState.DOWN, LinkState.UP] since there should be no new events at all?

await asyncio.sleep(20)
alpha_events = client_beta.get_link_state_events(alpha.public_key)
beta_events = client_alpha.get_link_state_events(beta.public_key)
await client_alpha.wait_for_new_link_state(beta.public_key, [LinkState.UP])
Copy link
Contributor

@tomasz-grz tomasz-grz Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also be some shared condition for every test case to follow DRY principles

@@ -168,18 +190,22 @@ async def test_event_link_state_peers_exchanging_data_for_a_long_time(
conn.connection for conn in env.connections
]

await client_alpha.wait_for_new_link_state(beta.public_key, [LinkState.UP])
await client_beta.wait_for_new_link_state(alpha.public_key, [LinkState.UP])

for _ in range(0, 40):
await asyncio.sleep(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

40 seconds of sleep 🛌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants