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

Function addInstancesPeriodically

ring/util_test.go:232–257  ·  view source on GitHub ↗
(ring *Ring)

Source from the content-addressed store, hash-verified

230}
231
232func addInstancesPeriodically(ring *Ring) chan struct{} {
233 // Keep changing the ring.
234 done := make(chan struct{})
235
236 go func() {
237 for {
238 select {
239 case <-done:
240 return
241 case <-time.After(time.Second):
242 ring.mtx.Lock()
243 ringDesc := ring.ringDesc
244 instanceID := fmt.Sprintf("127.0.0.%d", len(ringDesc.Ingesters)+1)
245 ringDesc.Ingesters[instanceID] = InstanceDesc{Id: instanceID, Addr: instanceID, State: ACTIVE, Timestamp: time.Now().Unix()}
246 ring.ringDesc = ringDesc
247 ring.ringTokens = ringDesc.GetTokens()
248 ring.ringTokensByZone = ringDesc.getTokensByZone()
249 ring.ringInstanceByToken = ringDesc.getTokensInfo()
250 ring.ringZones = getZones(ringDesc.getTokensByZone())
251
252 ring.mtx.Unlock()
253 }
254 }
255 }()
256 return done
257}
258
259func TestWaitRingStability_ShouldReturnErrorIfInstancesAddedAndMaxWaitingIsReached(t *testing.T) {
260 t.Parallel()

Calls 5

getZonesFunction · 0.85
getTokensByZoneMethod · 0.80
getTokensInfoMethod · 0.80
AfterMethod · 0.65
GetTokensMethod · 0.45

Tested by

no test coverage detected