MCPcopy Create free account
hub / github.com/cortexproject/cortex / addInstancesPeriodically

Function addInstancesPeriodically

pkg/ring/util_test.go:136–161  ·  view source on GitHub ↗
(ring *Ring)

Source from the content-addressed store, hash-verified

134}
135
136func addInstancesPeriodically(ring *Ring) chan struct{} {
137 // Keep changing the ring.
138 done := make(chan struct{})
139
140 go func() {
141 for {
142 select {
143 case <-done:
144 return
145 case <-time.After(time.Second):
146 ring.mtx.Lock()
147 ringDesc := ring.ringDesc
148 instanceID := fmt.Sprintf("127.0.0.%d", len(ringDesc.Ingesters)+1)
149 ringDesc.Ingesters[instanceID] = InstanceDesc{Addr: instanceID, State: ACTIVE, Timestamp: time.Now().Unix()}
150 ring.ringDesc = ringDesc
151 ring.ringTokens = ringDesc.GetTokens()
152 ring.ringTokensByZone = ringDesc.getTokensByZone()
153 ring.ringInstanceByToken = ringDesc.getTokensInfo()
154 ring.ringZones = getZones(ringDesc.getTokensByZone())
155
156 ring.mtx.Unlock()
157 }
158 }
159 }()
160 return done
161}
162
163func TestWaitRingStability_ShouldReturnErrorIfInstancesAddedAndMaxWaitingIsReached(t *testing.T) {
164 t.Parallel()

Calls 5

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

Tested by

no test coverage detected