(t *testing.T)
| 90 | } |
| 91 | |
| 92 | func TestReset(t *testing.T) { |
| 93 | c, closer := NewInMemoryClient(codec.String{}, testLogger{}, prometheus.NewPedanticRegistry()) |
| 94 | t.Cleanup(func() { |
| 95 | assert.NoError(t, closer.Close()) |
| 96 | }) |
| 97 | |
| 98 | const key = "test" |
| 99 | const max = 5 |
| 100 | |
| 101 | ch := make(chan error) |
| 102 | go func() { |
| 103 | defer close(ch) |
| 104 | for i := 0; i <= max; i++ { |
| 105 | t.Log("ts", time.Now(), "msg", "writing value", "val", i) |
| 106 | _, _ = c.kv.Put(&consul.KVPair{Key: key, Value: []byte(fmt.Sprintf("%d", i))}, nil) |
| 107 | if i == 1 { |
| 108 | c.kv.(*mockKV).ResetIndex() |
| 109 | } |
| 110 | if i == 2 { |
| 111 | c.kv.(*mockKV).ResetIndexForKey(key) |
| 112 | } |
| 113 | time.Sleep(10 * time.Millisecond) |
| 114 | } |
| 115 | }() |
| 116 | |
| 117 | observed := observeValueForSomeTime(t, c, key, 25*max*time.Millisecond) |
| 118 | |
| 119 | // wait until updater finishes |
| 120 | <-ch |
| 121 | |
| 122 | // Let's see how many updates we have observed. Given the rate limit and our observing time, we should see all numeric values |
| 123 | if testing.Verbose() { |
| 124 | t.Log(observed) |
| 125 | } |
| 126 | if len(observed) < max { |
| 127 | t.Error("Expected all values, got", observed) |
| 128 | } else if observed[len(observed)-1] != fmt.Sprintf("%d", max) { |
| 129 | t.Error("Expected to see last written value, got", observed) |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | func observeValueForSomeTime(t *testing.T, client *Client, key string, timeout time.Duration) []string { |
| 134 | t.Helper() |
nothing calls this directly
no test coverage detected