mirror of
https://github.com/usual2970/certimate.git
synced 2025-07-28 11:08:34 +00:00
.github
.vscode
docker
internal
app
applicant
acme_ca.go
acme_user.go
applicant.go
applicant_test.go
providers.go
certificate
deployer
domain
notify
pkg
repository
rest
scheduler
statistics
workflow
migrations
ui
.dockerignore
.editorconfig
.gitignore
.goreleaser.yml
CHANGELOG.md
CONTRIBUTING.md
CONTRIBUTING_EN.md
Dockerfile
LICENSE.md
Makefile
README.md
README_EN.md
go.mod
go.sum
main.go
nixpacks.toml
45 lines
866 B
Go
45 lines
866 B
Go
package applicant_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"golang.org/x/time/rate"
|
|
)
|
|
|
|
func TestRateLimit(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
burst int
|
|
rate rate.Limit
|
|
}{
|
|
{
|
|
name: "test1",
|
|
burst: 300,
|
|
rate: rate.Limit(float64(1) / float64(20)),
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
rl := rate.NewLimiter(tt.rate, tt.burst)
|
|
if rl.Burst() != tt.burst {
|
|
t.Errorf("Burst() = %v, want %v", rl.Burst(), tt.burst)
|
|
}
|
|
if rl.Limit() != tt.rate {
|
|
t.Errorf("Limit() = %v, want %v", rl.Limit(), tt.rate)
|
|
}
|
|
|
|
t.Log("consume all tokens at once", rl.AllowN(time.Now(), tt.burst))
|
|
|
|
t.Log("consume more", rl.Allow())
|
|
|
|
time.Sleep(time.Second * 5)
|
|
t.Log("consume after 5 seconds", rl.Allow())
|
|
|
|
time.Sleep(time.Second * 20)
|
|
t.Log("consume after 20 seconds", rl.Allow())
|
|
})
|
|
}
|
|
}
|