(t *testing.T)
| 109 | } |
| 110 | |
| 111 | func 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 | |
| 146 | func TestWatchKeyNoRateLimit(t *testing.T) { |
| 147 | c, closer := NewInMemoryClientWithConfig(codec.String{}, Config{ |
nothing calls this directly
no test coverage detected