Skip to content

fix(alertmanager): Fix flaky TestMultitenantAlertmanager_InitialSyncFailureWithSharding#7498

Open
yeya24 wants to merge 1 commit intomasterfrom
fix/alertmanager-initial-sync-flaky-test
Open

fix(alertmanager): Fix flaky TestMultitenantAlertmanager_InitialSyncFailureWithSharding#7498
yeya24 wants to merge 1 commit intomasterfrom
fix/alertmanager-initial-sync-flaky-test

Conversation

@yeya24
Copy link
Copy Markdown
Contributor

@yeya24 yeya24 commented May 10, 2026

What this PR does

Fixes the flaky TestMultitenantAlertmanager_InitialSyncFailureWithSharding test in pkg/alertmanager.

Root Cause

The test asserts require.False(t, am.ringLifecycler.IsRegistered()) immediately after the service transitions to Failed state. 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:

  1. The stopping() function unregistering the instance
  2. The lifecycler's auto-join goroutine re-registering it
  3. The test checking IsRegistered()

Fix

Replace the immediate require.False assertion with require.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.

…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>
@yeya24 yeya24 force-pushed the fix/alertmanager-initial-sync-flaky-test branch from b6366fc to 808ccf6 Compare May 11, 2026 00:57
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/alertmanager lgtm This PR has been approved by a maintainer size/XS type/flaky-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants