MCPcopy
hub / github.com/uber-go/zap / TestMockClock_NewTicker

Function TestMockClock_NewTicker

internal/ztest/clock_test.go:31–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29)
30
31func TestMockClock_NewTicker(t *testing.T) {
32 var n atomic.Int32
33 clock := NewMockClock()
34
35 done := make(chan struct{})
36 defer func() { <-done }() // wait for end
37
38 quit := make(chan struct{})
39 // Create a channel to increment every microsecond.
40 go func(ticker *time.Ticker) {
41 defer close(done)
42 for {
43 select {
44 case <-quit:
45 ticker.Stop()
46 return
47 case <-ticker.C:
48 n.Add(1)
49 }
50 }
51 }(clock.NewTicker(time.Microsecond))
52
53 // Move clock forward.
54 clock.Add(2 * time.Microsecond)
55 assert.Equal(t, int32(2), n.Load())
56 close(quit)
57}
58
59func TestMockClock_NewTicker_slowConsumer(t *testing.T) {
60 clock := NewMockClock()

Callers

nothing calls this directly

Calls 4

AddMethod · 0.95
NewTickerMethod · 0.95
NewMockClockFunction · 0.85
StopMethod · 0.80

Tested by

no test coverage detected