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

Function TestWatchKeyWithNoStartValue

pkg/ring/kv/consul/client_test.go:229–258  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

227}
228
229func TestWatchKeyWithNoStartValue(t *testing.T) {
230 c, closer := NewInMemoryClient(codec.String{}, testLogger{}, prometheus.NewPedanticRegistry())
231 t.Cleanup(func() {
232 assert.NoError(t, closer.Close())
233 })
234
235 const key = "test"
236
237 go func() {
238 time.Sleep(100 * time.Millisecond)
239 _, err := c.kv.Put(&consul.KVPair{Key: key, Value: []byte("start")}, nil)
240 require.NoError(t, err)
241
242 time.Sleep(100 * time.Millisecond)
243 _, err = c.kv.Put(&consul.KVPair{Key: key, Value: []byte("end")}, nil)
244 require.NoError(t, err)
245 }()
246
247 ctx, fn := context.WithTimeout(context.Background(), 300*time.Millisecond)
248 defer fn()
249
250 reported := 0
251 c.WatchKey(ctx, key, func(i any) bool {
252 reported++
253 return reported != 2
254 })
255
256 // we should see both start and end values.
257 require.Equal(t, 2, reported)
258}
259
260type testLogger struct {
261}

Callers

nothing calls this directly

Calls 5

NewInMemoryClientFunction · 0.70
CloseMethod · 0.65
PutMethod · 0.65
WatchKeyMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected