fix(alertmanager): Fix flaky TestMultitenantAlertmanager_InitialSyncFailureWithSharding#7498
Open
fix(alertmanager): Fix flaky TestMultitenantAlertmanager_InitialSyncFailureWithSharding#7498
Conversation
…ailureWithSharding
The test was racy because the ring lifecycler background goroutine
could re-register the instance ("instance missing in the ring, adding
it back") between the service failing and the test asserting
IsRegistered() == false.
Fix by using require.Eventually to poll for the unregistered state,
giving the stopping process time to fully unregister.
Signed-off-by: Ben Ye <benye@amazon.com>
b6366fc to
808ccf6
Compare
SungJin1212
approved these changes
May 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
Fixes the flaky
TestMultitenantAlertmanager_InitialSyncFailureWithShardingtest inpkg/alertmanager.Root Cause
The test asserts
require.False(t, am.ringLifecycler.IsRegistered())immediately after the service transitions toFailedstate. However, the ring lifecycler has a background goroutine that detects the instance is missing from the ring and re-registers it ("instance missing in the ring, adding it back"). There's a race between:stopping()function unregistering the instanceIsRegistered()Fix
Replace the immediate
require.Falseassertion withrequire.Eventually, polling for the unregistered state with a 5s timeout and 100ms interval. This gives the stopping process time to fully unregister the instance.Verification
Ran the test 5 times — all pass consistently.