You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I added a modified version of the example tests into my project to see what results we get on our GitLab runners and they are not what I expected when the iteration runs some extra loops.
The modified tests are very plain, essentially I just replaced the print statement with t.Log and the loop runs more iterations.
func TestRateLimit_Example_default(t *testing.T) {
rl := ratelimit.New(100) // per second, some slack.
rl.Take() // Initialize.
time.Sleep(time.Millisecond * 45) // Let some time pass.
prev := time.Now()
for i := 0; i < 50; i++ {
now := rl.Take()
if i > 0 {
t.Log(i, now.Sub(prev).Round(time.Millisecond*2))
}
prev = now
}
t.Fail() // just to see the output
// Output:
// 1 0s
// 2 0s
// 3 0s
// 4 4ms
// 5 10ms
// 6 10ms
// 7 10ms
// 8 10ms
// 9 10ms
}
and
func TestRateLimit_Example_withoutSlack(t *testing.T) {
rl := ratelimit.New(100, ratelimit.WithoutSlack) // per second, no slack.
prev := time.Now()
for i := 0; i < 50; i++ {
now := rl.Take()
if i > 0 {
t.Log(i, now.Sub(prev))
}
prev = now
}
t.Fail() // just to see the output
// Output:
// 1 10ms
// 2 10ms
// 3 10ms
// 4 10ms
// 5 10ms
}
The project is based on Go 1.21 and is built with
ENV CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64
RUN --mount=target=. \
--mount=type=cache,target=/root/.cache/go-build \
go build -a -tags netgo -ldflags "-w -s" -o "/bin/" ./cmd/...
The text was updated successfully, but these errors were encountered:
Hi, I added a modified version of the example tests into my project to see what results we get on our GitLab runners and they are not what I expected when the iteration runs some extra loops.
Results:
and
The modified tests are very plain, essentially I just replaced the print statement with t.Log and the loop runs more iterations.
and
The project is based on Go 1.21 and is built with
The text was updated successfully, but these errors were encountered: