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

Function TestWatchKeyWithNoStartValue

kv/consul/client_test.go:151–180  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

149}
150
151func TestWatchKeyWithNoStartValue(t *testing.T) {
152 c, closer := NewInMemoryClient(codec.String{}, testLogger{}, prometheus.NewPedanticRegistry())
153 t.Cleanup(func() {
154 assert.NoError(t, closer.Close())
155 })
156
157 const key = "test"
158
159 go func() {
160 time.Sleep(100 * time.Millisecond)
161 _, err := c.kv.Put(&consul.KVPair{Key: key, Value: []byte("start")}, nil)
162 require.NoError(t, err)
163
164 time.Sleep(100 * time.Millisecond)
165 _, err = c.kv.Put(&consul.KVPair{Key: key, Value: []byte("end")}, nil)
166 require.NoError(t, err)
167 }()
168
169 ctx, fn := context.WithTimeout(context.Background(), 300*time.Millisecond)
170 defer fn()
171
172 reported := 0
173 c.WatchKey(ctx, key, func(interface{}) bool {
174 reported++
175 return reported != 2
176 })
177
178 // we should see both start and end values.
179 require.Equal(t, 2, reported)
180}
181
182type testLogger struct {
183}

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected