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

Function TestWatchKeyWithRateLimit

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

Source from the content-addressed store, hash-verified

109}
110
111func TestWatchKeyWithRateLimit(t *testing.T) {
112 c, closer := NewInMemoryClientWithConfig(codec.String{}, Config{
113 WatchKeyRateLimit: 5.0,
114 WatchKeyBurstSize: 1,
115 }, testLogger{}, prometheus.NewPedanticRegistry())
116 t.Cleanup(func() {
117 assert.NoError(t, closer.Close())
118 })
119
120 const key = "test"
121 const max = 100
122
123 ch := writeValuesToKV(t, c, key, 0, max, 10*time.Millisecond)
124
125 observed := observeValueForSomeTime(t, c, key, 1200*time.Millisecond) // little over 1 second
126
127 // wait until updater finishes
128 <-ch
129
130 if testing.Verbose() {
131 t.Log(observed)
132 }
133 // Let's see how many updates we have observed. Given the rate limit and our observing time, it should be 6
134 // We should also have seen one of the later values, as we're observing for longer than a second, so rate limit should allow
135 // us to see it.
136 if len(observed) < 5 || len(observed) > 10 {
137 t.Error("Expected ~6 observed values, got", observed)
138 }
139 last := observed[len(observed)-1]
140 n, _ := strconv.Atoi(last)
141 if n < max/2 {
142 t.Error("Expected to see high last observed value, got", observed)
143 }
144}
145
146func TestWatchKeyNoRateLimit(t *testing.T) {
147 c, closer := NewInMemoryClientWithConfig(codec.String{}, Config{

Callers

nothing calls this directly

Calls 6

writeValuesToKVFunction · 0.85
observeValueForSomeTimeFunction · 0.85
CloseMethod · 0.65
LogMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected