MCPcopy Create free account
hub / github.com/diillson/chatcli / TestTimer_StartStopElapsed

Function TestTimer_StartStopElapsed

cli/metrics/timer_test.go:14–42  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestTimer_StartStopElapsed(t *testing.T) {
15 tm := NewTimer()
16 if tm.IsRunning() {
17 t.Fatal("new timer should not be running")
18 }
19
20 var ticks int
21 tm.Start(context.Background(), func(time.Duration) { ticks++ })
22 if !tm.IsRunning() {
23 t.Fatal("timer should be running after Start")
24 }
25 if tm.Elapsed() < 0 {
26 t.Error("elapsed should be non-negative while running")
27 }
28 time.Sleep(20 * time.Millisecond)
29
30 d := tm.Stop()
31 if d <= 0 {
32 t.Errorf("stopped duration should be positive, got %v", d)
33 }
34 if tm.IsRunning() {
35 t.Error("timer should not be running after Stop")
36 }
37 // Under `go test` stdout is a pipe, not a TTY, so the animation gate keeps
38 // the displayFunc from firing — no spinner noise leaks to captured output.
39 if ticks != 0 {
40 t.Errorf("displayFunc must not fire when stdout is not a terminal, got %d", ticks)
41 }
42}
43
44func TestTimer_StopWhenNotRunning(t *testing.T) {
45 tm := NewTimer()

Callers

nothing calls this directly

Calls 7

IsRunningMethod · 0.95
StartMethod · 0.95
ElapsedMethod · 0.95
StopMethod · 0.95
NewTimerFunction · 0.85
ErrorfMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected