ExpectMapExpvarMetricDeltaWithDeadline returns a deferrable function which tests if the expvar map metric with name and key has changed by delta within the given deadline, once the function begins. Before returning, it fetches the original value for comparison.
(tb testing.TB, name, key string, want int64)
| 46 | |
| 47 | // ExpectMapExpvarMetricDeltaWithDeadline returns a deferrable function which tests if the expvar map metric with name and key has changed by delta within the given deadline, once the function begins. Before returning, it fetches the original value for comparison. |
| 48 | func ExpectMapExpvarDeltaWithDeadline(tb testing.TB, name, key string, want int64) func() { |
| 49 | tb.Helper() |
| 50 | deadline := defaultDoOrTimeoutDeadline |
| 51 | startVar := TestGetExpvar(tb, name).(*expvar.Map).Get(key) |
| 52 | var start int64 |
| 53 | if startVar != nil { |
| 54 | start = startVar.(*expvar.Int).Value() |
| 55 | } |
| 56 | check := func() (bool, error) { |
| 57 | tb.Helper() |
| 58 | nowVar := TestGetExpvar(tb, name).(*expvar.Map).Get(key) |
| 59 | var now int64 |
| 60 | if nowVar != nil { |
| 61 | now = nowVar.(*expvar.Int).Value() |
| 62 | } |
| 63 | return now-start == want, nil |
| 64 | } |
| 65 | return func() { |
| 66 | tb.Helper() |
| 67 | ok, err := DoOrTimeout(check, deadline, 10*time.Millisecond) |
| 68 | FatalIfErr(tb, err) |
| 69 | if !ok { |
| 70 | nowVar := TestGetExpvar(tb, name).(*expvar.Map).Get(key) |
| 71 | var now int64 |
| 72 | if nowVar != nil { |
| 73 | now = nowVar.(*expvar.Int).Value() |
| 74 | } |
| 75 | tb.Errorf("Did not see %s[%s] have delta by deadline: got %v - %v = %d, want %d", name, key, now, start, now-start, want) |
| 76 | } |
| 77 | } |
| 78 | } |