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

[tests] make instance reincarnation tests less racy #7295

Merged
merged 1 commit into from
Dec 21, 2024
Merged

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Dec 20, 2024

A possible test flake exists in the tests for instance reincarnation. This is caused by a race that occurs when the request to simulate an instance's state transition is sent to the simulated sled-agent before an instance-start saga sends the request to start the instance to that sled-agent. When this occurs, the simulated state transition is lost, and the test keeps waiting for it forever. See this comment for details.

This commit resolves this by adding a new
instance_wait_for_simulated_transition helper, which is identical to instance_wait_for_state, but with the addition of instance_poke requests every time the instance is not observed to be in the desired state. This is a bit of a blunt instrument, but it ensures that the simulated sled-agent will always be told to simulate a state transition after it's requested by the control plane.

Hopefully fixes #6727

A possible test flake exists in the tests for instance reincarnation.
This is caused by a race that occurs when the request to simulate an
instance's state transition is sent to the simulated sled-agent *before*
an instance-start saga sends the request to start the instance to that
sled-agent. When this occurs, the simulated state transition is lost,
and the test keeps waiting for it forever. See [this comment][1] for
details.

This commit resolves this by adding a new
`instance_wait_for_simulated_transition` helper, which is identical to
`instance_wait_for_state`, but with the addition of `instance_poke`
requests every time the instance is not observed to be in the desired
state. This is a bit of a blunt instrument, but it ensures that the
simulated sled-agent will always be told to simulate a state transition
after it's requested by the control plane.

Hopefully fixes #6727

[1]: #6727 (comment)
Copy link
Contributor

@gjcolombo gjcolombo left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix!

There's a small part of me that wonders if we should have some sort of construct in simulated sled agent to try to do this (along the lines of "poke this object, but if there are no transitions queued, wait for one to be queued before returning"). But if I were going to spend a bunch of time hacking on the simulated agent, I'd probably want to make it have less logic and not more, so the approach you've taken here seems good to me.

@hawkw
Copy link
Member Author

hawkw commented Dec 21, 2024

There's a small part of me that wonders if we should have some sort of construct in simulated sled agent to try to do this (along the lines of "poke this object, but if there are no transitions queued, wait for one to be queued before returning").

I also think it could be worth revisiting how the simulated sled-agent is controlled. My naïve thought for how we might avoid these kinds of races would be something where the sled-agent is given an entire test plan up front. The test would say "expect the control plane to ask you to do these things in this order, and do these state transitions in response". Then, at the very end of the test, we'd say "did you see exactly the requests from Nexus I told you were coming?" and panics if it didn't. But, that feels like a pretty substantial rewrite of the simulated sled-agent, and we may have some tests that can't easily be represented that way...

For now, this approach is certainly a blunt instrument, but it felt like the least invasive change to fix the test flake. Possibly some of the other tests should also be changed to use the new helper...

@hawkw hawkw enabled auto-merge (squash) December 21, 2024 00:42
@hawkw hawkw merged commit ef65ae6 into main Dec 21, 2024
16 checks passed
@hawkw hawkw deleted the eliza/fix-6727 branch December 21, 2024 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants