Skip to content

Commit

Permalink
Increase test durations x10 to fix flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bancek committed May 20, 2024
1 parent 258932c commit 3b78811
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions throttle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func Test_NoPings(t *testing.T) {
var wg sync.WaitGroup
throttle := throttle.NewThrottle(time.Millisecond, false)
throttle := throttle.NewThrottle(10*time.Millisecond, false)

count := 0

Expand All @@ -22,7 +22,7 @@ func Test_NoPings(t *testing.T) {
}
}()

time.Sleep(10 * time.Millisecond)
time.Sleep(100 * time.Millisecond)
throttle.Stop()

wg.Wait()
Expand All @@ -35,7 +35,7 @@ func Test_NoPings(t *testing.T) {
func Test_MultiPingInOnePeriod(t *testing.T) {
var wg sync.WaitGroup

throttle := throttle.NewThrottle(time.Millisecond, false)
throttle := throttle.NewThrottle(10*time.Millisecond, false)
count := 0

wg.Add(1)
Expand All @@ -50,7 +50,7 @@ func Test_MultiPingInOnePeriod(t *testing.T) {
throttle.Trigger()
}

time.Sleep(5 * time.Millisecond)
time.Sleep(50 * time.Millisecond)

throttle.Stop()

Expand All @@ -64,7 +64,7 @@ func Test_MultiPingInOnePeriod(t *testing.T) {
func Test_MultiPingInMultiplePeriod(t *testing.T) {
var wg sync.WaitGroup

throttle := throttle.NewThrottle(time.Millisecond, false)
throttle := throttle.NewThrottle(10*time.Millisecond, false)
count := 0

wg.Add(1)
Expand All @@ -76,11 +76,11 @@ func Test_MultiPingInMultiplePeriod(t *testing.T) {
}()

for i := 0; i < 5; i++ {
time.Sleep(time.Millisecond / 4)
time.Sleep(10 * time.Millisecond / 4)
throttle.Trigger()
}

time.Sleep(5 * time.Millisecond)
time.Sleep(50 * time.Millisecond)

throttle.Stop()

Expand All @@ -94,7 +94,7 @@ func Test_MultiPingInMultiplePeriod(t *testing.T) {
func Test_TrailingMultiPingInOnePeriod(t *testing.T) {
var wg sync.WaitGroup

throttle := throttle.NewThrottle(time.Millisecond, true)
throttle := throttle.NewThrottle(10*time.Millisecond, true)
count := 0

cond := sync.NewCond(&sync.Mutex{})
Expand All @@ -118,7 +118,7 @@ func Test_TrailingMultiPingInOnePeriod(t *testing.T) {
throttle.Trigger()
throttle.Trigger()

time.Sleep(5 * time.Millisecond)
time.Sleep(50 * time.Millisecond)

throttle.Stop()

Expand All @@ -132,15 +132,15 @@ func Test_TrailingMultiPingInOnePeriod(t *testing.T) {
func Test_ThrottleFunc(t *testing.T) {
count := 0

throttle := throttle.ThrottleFunc(time.Millisecond, false, func() {
throttle := throttle.ThrottleFunc(10*time.Millisecond, false, func() {
count += 1
})

for i := 0; i < 5; i++ {
throttle.Trigger()
}

time.Sleep(5 * time.Millisecond)
time.Sleep(50 * time.Millisecond)

throttle.Stop()

Expand Down

0 comments on commit 3b78811

Please sign in to comment.