(t *testing.T)
| 147 | } |
| 148 | |
| 149 | func TestLifecycler_HealthyInstancesCount(t *testing.T) { |
| 150 | t.Parallel() |
| 151 | |
| 152 | ringStore, closer := consul.NewInMemoryClient(GetCodec(), log.NewNopLogger(), nil) |
| 153 | t.Cleanup(func() { assert.NoError(t, closer.Close()) }) |
| 154 | |
| 155 | var ringConfig Config |
| 156 | flagext.DefaultValues(&ringConfig) |
| 157 | ringConfig.KVStore.Mock = ringStore |
| 158 | |
| 159 | ctx := context.Background() |
| 160 | |
| 161 | // Add the first ingester to the ring |
| 162 | lifecyclerConfig1 := testLifecyclerConfig(ringConfig, "ing1") |
| 163 | lifecyclerConfig1.HeartbeatPeriod = 100 * time.Millisecond |
| 164 | lifecyclerConfig1.JoinAfter = 100 * time.Millisecond |
| 165 | |
| 166 | lifecycler1, err := NewLifecycler(lifecyclerConfig1, &nopFlushTransferer{}, "ingester", ringKey, true, log.NewNopLogger(), nil) |
| 167 | require.NoError(t, err) |
| 168 | assert.Equal(t, 0, lifecycler1.HealthyInstancesCount()) |
| 169 | |
| 170 | require.NoError(t, services.StartAndAwaitRunning(ctx, lifecycler1)) |
| 171 | defer services.StopAndAwaitTerminated(ctx, lifecycler1) // nolint:errcheck |
| 172 | |
| 173 | // Assert the first ingester joined the ring |
| 174 | test.Poll(t, 1000*time.Millisecond, true, func() interface{} { |
| 175 | return lifecycler1.HealthyInstancesCount() == 1 |
| 176 | }) |
| 177 | |
| 178 | // Add the second ingester to the ring |
| 179 | lifecyclerConfig2 := testLifecyclerConfig(ringConfig, "ing2") |
| 180 | lifecyclerConfig2.HeartbeatPeriod = 100 * time.Millisecond |
| 181 | lifecyclerConfig2.JoinAfter = 100 * time.Millisecond |
| 182 | |
| 183 | lifecycler2, err := NewLifecycler(lifecyclerConfig2, &nopFlushTransferer{}, "ingester", ringKey, true, log.NewNopLogger(), nil) |
| 184 | require.NoError(t, err) |
| 185 | assert.Equal(t, 0, lifecycler2.HealthyInstancesCount()) |
| 186 | |
| 187 | require.NoError(t, services.StartAndAwaitRunning(ctx, lifecycler2)) |
| 188 | defer services.StopAndAwaitTerminated(ctx, lifecycler2) // nolint:errcheck |
| 189 | |
| 190 | // Assert the second ingester joined the ring |
| 191 | test.Poll(t, 1000*time.Millisecond, true, func() interface{} { |
| 192 | return lifecycler2.HealthyInstancesCount() == 2 |
| 193 | }) |
| 194 | |
| 195 | // Assert the first ingester count is updated |
| 196 | test.Poll(t, 1000*time.Millisecond, true, func() interface{} { |
| 197 | return lifecycler1.HealthyInstancesCount() == 2 |
| 198 | }) |
| 199 | } |
| 200 | |
| 201 | func TestLifecycler_HealthyInstancesInZoneCount(t *testing.T) { |
| 202 | t.Parallel() |
nothing calls this directly
no test coverage detected