MCPcopy
hub / github.com/lonng/nano / TestNewAfterTimer

Function TestNewAfterTimer

scheduler/timer_test.go:68–104  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

66}
67
68func TestNewAfterTimer(t *testing.T) {
69 var exists = struct {
70 timers int
71 createdTimes int
72 closingTimers int
73 }{
74 timers: len(timerManager.timers),
75 createdTimes: len(timerManager.createdTimer),
76 closingTimers: len(timerManager.closingTimer),
77 }
78
79 const tc = 1000
80 var counter int64
81 for i := 0; i < tc; i++ {
82 NewAfterTimer(1*time.Millisecond, func() {
83 atomic.AddInt64(&counter, 1)
84 })
85 }
86
87 <-time.After(5 * time.Millisecond)
88 cron()
89 if counter != tc {
90 t.Fatalf("expect: %d, got: %d", tc, counter)
91 }
92
93 if len(timerManager.timers) != exists.timers {
94 t.Fatalf("timers: %d", len(timerManager.timers))
95 }
96
97 if len(timerManager.createdTimer) != exists.createdTimes {
98 t.Fatalf("createdTimer: %d", len(timerManager.createdTimer))
99 }
100
101 if len(timerManager.closingTimer) != exists.closingTimers {
102 t.Fatalf("closingTimer: %d", len(timerManager.closingTimer))
103 }
104}

Callers

nothing calls this directly

Calls 3

NewAfterTimerFunction · 0.85
cronFunction · 0.85
FatalfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…