Files
timer/staged_timer_test.go
zeekay 257fab9d01 refactor: consolidate Meter type, remove duplicate interface
- Remove meter.go (duplicate Meter interface)
- Keep concrete Meter struct in clock.go
- Add new timer files (adaptive, staged, stopped)
2026-01-09 14:50:46 -08:00

48 lines
835 B
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package timer
import (
"sync"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestSingleStagedTimer(t *testing.T) {
wg := sync.WaitGroup{}
wg.Add(1)
ticks := 1
i := 0
timer := NewStagedTimer(func() (time.Duration, bool) {
defer wg.Done()
i++
return 0, false
})
go timer.Dispatch()
timer.SetTimeoutIn(time.Millisecond)
wg.Wait()
require.Equal(t, i, ticks)
}
func TestMultiStageTimer(t *testing.T) {
wg := sync.WaitGroup{}
ticks := 3
wg.Add(ticks)
i := 0
timer := NewStagedTimer(func() (time.Duration, bool) {
defer wg.Done()
i++
return time.Millisecond, i < ticks
})
go timer.Dispatch()
timer.SetTimeoutIn(time.Millisecond)
wg.Wait()
require.Equal(t, i, ticks)
}