github.com/benz9527/xboot@v0.0.0-20240504061247-c23f15593274/timer/x_timing_wheels_v2_windows_test.go (about) 1 //go:build windows 2 // +build windows 3 4 package timer 5 6 import ( 7 "context" 8 "errors" 9 "testing" 10 "time" 11 12 "github.com/benz9527/xboot/lib/hrtime" 13 "github.com/benz9527/xboot/observability" 14 "github.com/stretchr/testify/assert" 15 "go.uber.org/automaxprocs/maxprocs" 16 ) 17 18 func TestXTimingWheelsV2_ScheduleFunc_windowsClock_1MsInfinite(t *testing.T) { 19 _, _ = maxprocs.Set(maxprocs.Min(4), maxprocs.Logger(t.Logf)) 20 hrtime.ClockInit() 21 observability.InitAppStats(context.Background(), "window1msInfinite") 22 defer func() { 23 _ = hrtime.ResetTimeResolutionFrom1ms() 24 }() 25 ctx, cancel := context.WithTimeoutCause(context.Background(), 5*time.Second, errors.New("timeout")) 26 defer cancel() 27 tw := NewXTimingWheelsV2( 28 ctx, 29 WithTimingWheelTimeSource(WindowsClock), 30 WithTimingWheelsStats(), 31 withTimingWheelsDebugStatsInit(5), 32 ) 33 34 delays := []time.Duration{ 35 time.Millisecond, 36 } 37 schedFn := func() Scheduler { 38 return NewInfiniteScheduler(delays...) 39 } 40 assert.NotNil(t, schedFn()) 41 loop := 20 42 tasks := make([]Task, loop) 43 for i := range loop { 44 var err error 45 tasks[i], err = tw.ScheduleFunc(schedFn, func(ctx context.Context, md JobMetadata) {}) 46 assert.NoError(t, err) 47 time.Sleep(2 * time.Millisecond) 48 } 49 50 <-ctx.Done() 51 time.Sleep(100 * time.Millisecond) 52 }