-
Notifications
You must be signed in to change notification settings - Fork 24
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
base: main
Are you sure you want to change the base?
LLT-5683: Increase constrains in link state testcases #909
Conversation
e02a96d
to
4b5ef12
Compare
4b5ef12
to
c1193b5
Compare
c1193b5
to
e93f34c
Compare
e93f34c
to
0ab9458
Compare
0ab9458
to
8aaa4d9
Compare
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]>
8aaa4d9
to
e2980ee
Compare
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: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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).
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: |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
35337a7
to
1051cc3
Compare
`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.
1051cc3
to
7c1d372
Compare
[ | ||
asyncio.create_task( | ||
client_alpha.wait_for_new_link_state( | ||
beta.public_key, [LinkState.DOWN] |
There was a problem hiding this comment.
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]) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
40 seconds of sleep 🛌
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