MCPcopy
hub / github.com/grafana/dskit / changeStatePeriodically

Function changeStatePeriodically

ring/util_test.go:300–329  ·  view source on GitHub ↗

Keep changing the ring in a way to avoid repeating the same set of states for at least 2 sec

(ring *Ring)

Source from the content-addressed store, hash-verified

298
299// Keep changing the ring in a way to avoid repeating the same set of states for at least 2 sec
300func changeStatePeriodically(ring *Ring) chan struct{} {
301 done := make(chan struct{})
302 go func() {
303 instanceToMutate := "instance-1"
304 states := []InstanceState{PENDING, JOINING, ACTIVE, LEAVING}
305 stateIdx := 0
306
307 for states[stateIdx] != ring.ringDesc.Ingesters[instanceToMutate].State {
308 stateIdx++
309 }
310
311 for {
312 select {
313 case <-done:
314 return
315 case <-time.After(time.Second):
316 stateIdx++
317 ring.mtx.Lock()
318 ringDesc := ring.ringDesc
319 desc := ringDesc.Ingesters[instanceToMutate]
320 desc.State = states[stateIdx%len(states)]
321 desc.Timestamp = time.Now().Unix()
322 ringDesc.Ingesters[instanceToMutate] = desc
323 ring.mtx.Unlock()
324 }
325 }
326 }()
327
328 return done
329}
330
331func TestWaitRingStability_ShouldReturnErrorIfInstanceStateIsChangingAndMaxWaitingIsReached(t *testing.T) {
332 t.Parallel()

Calls 1

AfterMethod · 0.65

Tested by

no test coverage detected