(t *testing.T)
| 199 | } |
| 200 | |
| 201 | func TestLifecycler_HealthyInstancesInZoneCount(t *testing.T) { |
| 202 | t.Parallel() |
| 203 | |
| 204 | ringStore, closer := consul.NewInMemoryClient(GetCodec(), log.NewNopLogger(), nil) |
| 205 | t.Cleanup(func() { assert.NoError(t, closer.Close()) }) |
| 206 | |
| 207 | var ringConfig Config |
| 208 | flagext.DefaultValues(&ringConfig) |
| 209 | ringConfig.KVStore.Mock = ringStore |
| 210 | |
| 211 | ctx := context.Background() |
| 212 | |
| 213 | // Add the first ingester to the ring |
| 214 | lifecyclerConfig1 := testLifecyclerConfig(ringConfig, "ing1") |
| 215 | lifecyclerConfig1.HeartbeatPeriod = 100 * time.Millisecond |
| 216 | lifecyclerConfig1.JoinAfter = 100 * time.Millisecond |
| 217 | lifecyclerConfig1.Zone = "zone-a" |
| 218 | |
| 219 | lifecycler1, err := NewLifecycler(lifecyclerConfig1, &nopFlushTransferer{}, "ingester", ringKey, true, log.NewNopLogger(), nil) |
| 220 | require.NoError(t, err) |
| 221 | assert.Equal(t, 0, lifecycler1.HealthyInstancesInZoneCount()) |
| 222 | |
| 223 | require.NoError(t, services.StartAndAwaitRunning(ctx, lifecycler1)) |
| 224 | defer services.StopAndAwaitTerminated(ctx, lifecycler1) // nolint:errcheck |
| 225 | |
| 226 | // Assert the first ingester joined the ring |
| 227 | test.Poll(t, time.Second, true, func() interface{} { |
| 228 | return lifecycler1.HealthyInstancesInZoneCount() == 1 |
| 229 | }) |
| 230 | |
| 231 | // Add the second ingester to the ring in the same zone |
| 232 | lifecyclerConfig2 := testLifecyclerConfig(ringConfig, "ing2") |
| 233 | lifecyclerConfig2.HeartbeatPeriod = 100 * time.Millisecond |
| 234 | lifecyclerConfig2.JoinAfter = 100 * time.Millisecond |
| 235 | lifecyclerConfig2.Zone = "zone-a" |
| 236 | |
| 237 | lifecycler2, err := NewLifecycler(lifecyclerConfig2, &nopFlushTransferer{}, "ingester", ringKey, true, log.NewNopLogger(), nil) |
| 238 | require.NoError(t, err) |
| 239 | assert.Equal(t, 0, lifecycler2.HealthyInstancesInZoneCount()) |
| 240 | |
| 241 | require.NoError(t, services.StartAndAwaitRunning(ctx, lifecycler2)) |
| 242 | defer services.StopAndAwaitTerminated(ctx, lifecycler2) // nolint:errcheck |
| 243 | |
| 244 | // Assert the second ingester joined the ring |
| 245 | test.Poll(t, time.Second, true, func() interface{} { |
| 246 | return lifecycler2.HealthyInstancesInZoneCount() == 2 |
| 247 | }) |
| 248 | |
| 249 | // Assert the first ingester count is updated |
| 250 | test.Poll(t, time.Second, true, func() interface{} { |
| 251 | return lifecycler1.HealthyInstancesInZoneCount() == 2 |
| 252 | }) |
| 253 | |
| 254 | // Add the third ingester to the ring in a different zone |
| 255 | lifecyclerConfig3 := testLifecyclerConfig(ringConfig, "ing3") |
| 256 | lifecyclerConfig3.HeartbeatPeriod = 100 * time.Millisecond |
| 257 | lifecyclerConfig3.JoinAfter = 100 * time.Millisecond |
| 258 | lifecyclerConfig3.Zone = "zone-b" |
nothing calls this directly
no test coverage detected