(t *testing.T)
| 31 | } |
| 32 | |
| 33 | func TestWatchKeyWithRateLimit(t *testing.T) { |
| 34 | c, closer := NewInMemoryClientWithConfig(codec.String{}, Config{ |
| 35 | WatchKeyRateLimit: 5.0, |
| 36 | WatchKeyBurstSize: 1, |
| 37 | }, testLogger{}, prometheus.NewPedanticRegistry()) |
| 38 | t.Cleanup(func() { |
| 39 | assert.NoError(t, closer.Close()) |
| 40 | }) |
| 41 | |
| 42 | const key = "test" |
| 43 | const max = 100 |
| 44 | |
| 45 | ch := writeValuesToKV(t, c, key, 0, max, 10*time.Millisecond) |
| 46 | |
| 47 | observed := observeValueForSomeTime(t, c, key, 1200*time.Millisecond) // little over 1 second |
| 48 | |
| 49 | // wait until updater finishes |
| 50 | <-ch |
| 51 | |
| 52 | if testing.Verbose() { |
| 53 | t.Log(observed) |
| 54 | } |
| 55 | // Let's see how many updates we have observed. Given the rate limit and our observing time, it should be 6 |
| 56 | // We should also have seen one of the later values, as we're observing for longer than a second, so rate limit should allow |
| 57 | // us to see it. |
| 58 | if len(observed) < 5 || len(observed) > 10 { |
| 59 | t.Error("Expected ~6 observed values, got", observed) |
| 60 | } |
| 61 | last := observed[len(observed)-1] |
| 62 | n, _ := strconv.Atoi(last) |
| 63 | if n < max/2 { |
| 64 | t.Error("Expected to see high last observed value, got", observed) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | func TestWatchKeyNoRateLimit(t *testing.T) { |
| 69 | c, closer := NewInMemoryClientWithConfig(codec.String{}, Config{ |
nothing calls this directly
no test coverage detected