Skip to content

Commit

Permalink
adding test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed Mar 11, 2024
1 parent 447634f commit b07db51
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions keyratelimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,30 @@ func TestMultiLimiter(t *testing.T) {
}()
wg.Wait()
}

func TestAdaptiveLimit(t *testing.T) {
limiter := ratelimit.New(context.TODO(), 1, time.Second)
require.NotNil(t, limiter)
start := time.Now()
expectedDuration := (time.Duration(3) * time.Second).Round(time.Millisecond)

go func() {
time.Sleep(2 * time.Second)

limiter.SetLimit(100)
}()

wg := &sync.WaitGroup{}

for i := 0; i < 100; i++ {
wg.Add(1)
go func() {
defer wg.Done()

limiter.Take()
}()
}
wg.Wait()

require.WithinDuration(t, start.Add(expectedDuration), time.Now(), 500*time.Millisecond)
}

0 comments on commit b07db51

Please sign in to comment.