| 36 | func (m *testMetrics) updateUnfinishedWork() { m.updateCalled <- struct{}{} } |
| 37 | |
| 38 | func TestMetricShutdown(t *testing.T) { |
| 39 | ch := make(chan struct{}) |
| 40 | m := &testMetrics{ |
| 41 | updateCalled: ch, |
| 42 | } |
| 43 | c := clock.NewFakeClock(time.Now()) |
| 44 | q := newQueue(c, m, time.Millisecond) |
| 45 | for !c.HasWaiters() { |
| 46 | // Wait for the go routine to call NewTicker() |
| 47 | time.Sleep(time.Millisecond) |
| 48 | } |
| 49 | |
| 50 | c.Step(time.Millisecond) |
| 51 | <-ch |
| 52 | q.ShutDown() |
| 53 | |
| 54 | c.Step(time.Hour) |
| 55 | select { |
| 56 | default: |
| 57 | return |
| 58 | case <-ch: |
| 59 | t.Errorf("Unexpected update after shutdown was called.") |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | type testMetric struct { |
| 64 | inc int64 |