docker.io/swarmkit/manager/dispatcher/period_test.go

21 lines
433 B
Go
Raw Normal View History

2024-04-24 10:03:53 +08:00
package dispatcher
import (
"testing"
"time"
)
func TestPeriodChooser(t *testing.T) {
period := 100 * time.Millisecond
epsilon := 50 * time.Millisecond
pc := newPeriodChooser(period, epsilon)
for i := 0; i < 1024; i++ {
ttl := pc.Choose()
if ttl < period-epsilon {
t.Fatalf("ttl elected below epsilon range: %v", ttl)
} else if ttl > period+epsilon {
t.Fatalf("ttl elected above epsilon range: %v", ttl)
}
}
}