Skip to content

Commit 41c6676

Browse files
stevesgalvinlin123
authored andcommitted
Fix StateReplicationWithSharding_InitialSyncFromPeers flaking. (cortexproject#4349)
The test is writing a single silence and checking a metric which indicates whether replicating the silence has been attempted yet. This is so we can check later on that no replication activity occurs. The assertions later on in the test are passing, but the first one is not, indicating that the replication doesn't trigger early enough. This makes sense because the replication is not synchronous with the writing of the silence. Signed-off-by: Steve Simpson <[email protected]> Signed-off-by: Alvin Lin <[email protected]>
1 parent bbdcfb3 commit 41c6676

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pkg/alertmanager/multitenant_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1817,7 +1817,14 @@ func TestAlertmanager_StateReplicationWithSharding_InitialSyncFromPeers(t *testi
18171817
{
18181818
metrics := registries.BuildMetricFamiliesPerUser()
18191819
assert.Equal(t, float64(1), metrics.GetSumOfGauges("cortex_alertmanager_silences"))
1820-
assert.Equal(t, float64(1), metrics.GetSumOfCounters("cortex_alertmanager_state_replication_total"))
1820+
}
1821+
// 2.c. Wait for the silence replication to be attempted; note this is asynchronous.
1822+
{
1823+
test.Poll(t, 5*time.Second, float64(1), func() interface{} {
1824+
metrics := registries.BuildMetricFamiliesPerUser()
1825+
return metrics.GetSumOfCounters("cortex_alertmanager_state_replication_total")
1826+
})
1827+
metrics := registries.BuildMetricFamiliesPerUser()
18211828
assert.Equal(t, float64(0), metrics.GetSumOfCounters("cortex_alertmanager_state_replication_failed_total"))
18221829
}
18231830

0 commit comments

Comments
 (0)