Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests on 32bit archs #129

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion limiter_atomic.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type atomicLimiter struct {
}

// newAtomicBased returns a new atomic based limiter.
func newAtomicBased(rate int, opts ...Option) *atomicLimiter {
func newAtomicBased(rate int64, opts ...Option) *atomicLimiter {
// TODO consider moving config building to the implementation
// independent code.
config := buildConfig(opts)
Expand Down
2 changes: 1 addition & 1 deletion limiter_atomic_int64.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type atomicInt64Limiter struct {
}

// newAtomicBased returns a new atomic based limiter.
func newAtomicInt64Based(rate int, opts ...Option) *atomicInt64Limiter {
func newAtomicInt64Based(rate int64, opts ...Option) *atomicInt64Limiter {
// TODO consider moving config building to the implementation
// independent code.
config := buildConfig(opts)
Expand Down
2 changes: 1 addition & 1 deletion limiter_mutexbased.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type mutexLimiter struct {
}

// newMutexBased returns a new mutex based limiter.
func newMutexBased(rate int, opts ...Option) *mutexLimiter {
func newMutexBased(rate int64, opts ...Option) *mutexLimiter {
// TODO consider moving config building to the implementation
// independent code.
config := buildConfig(opts)
Expand Down
2 changes: 1 addition & 1 deletion ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type config struct {
}

// New returns a Limiter that will limit to the given RPS.
func New(rate int, opts ...Option) Limiter {
func New(rate int64, opts ...Option) Limiter {
return newAtomicInt64Based(rate, opts...)
}

Expand Down
6 changes: 3 additions & 3 deletions ratelimit_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ func BenchmarkRateLimiter(b *testing.B) {
for _, procs := range []int{1, 4, 8, 16} {
runtime.GOMAXPROCS(procs)
for name, limiter := range map[string]Limiter{
"atomic": newAtomicBased(b.N * 1000000000000),
"atomic_int64": newAtomicInt64Based(b.N * 1000000000000),
"mutex": newMutexBased(b.N * 1000000000000),
"atomic": newAtomicBased(int64(b.N) * int64(1000000000000)),
"atomic_int64": newAtomicInt64Based(int64(b.N) * int64(1000000000000)),
"mutex": newMutexBased(int64(b.N) * int64(1000000000000)),
} {
for ng := 1; ng < 16; ng++ {
runner(b, name, procs, ng, limiter, count)
Expand Down
14 changes: 7 additions & 7 deletions ratelimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

type testRunner interface {
// createLimiter builds a limiter with given options.
createLimiter(int, ...Option) Limiter
createLimiter(int64, ...Option) Limiter
// takeOnceAfter attempts to Take at a specific time.
takeOnceAfter(time.Duration, Limiter)
// startTaking tries to Take() on passed in limiters in a loop/goroutine.
Expand All @@ -32,7 +32,7 @@ type runnerImpl struct {
t *testing.T

clock *clock.Mock
constructor func(int, ...Option) Limiter
constructor func(int64, ...Option) Limiter
count atomic.Int32
// maxDuration is the time we need to move into the future for a test.
// It's populated automatically based on assertCountAt/afterFunc.
Expand All @@ -44,23 +44,23 @@ type runnerImpl struct {
func runTest(t *testing.T, fn func(testRunner)) {
impls := []struct {
name string
constructor func(int, ...Option) Limiter
constructor func(int64, ...Option) Limiter
}{
{
name: "mutex",
constructor: func(rate int, opts ...Option) Limiter {
constructor: func(rate int64, opts ...Option) Limiter {
return newMutexBased(rate, opts...)
},
},
{
name: "atomic",
constructor: func(rate int, opts ...Option) Limiter {
constructor: func(rate int64, opts ...Option) Limiter {
return newAtomicBased(rate, opts...)
},
},
{
name: "atomic_int64",
constructor: func(rate int, opts ...Option) Limiter {
constructor: func(rate int64, opts ...Option) Limiter {
return newAtomicInt64Based(rate, opts...)
},
},
Expand Down Expand Up @@ -88,7 +88,7 @@ func runTest(t *testing.T, fn func(testRunner)) {
}

// createLimiter builds a limiter with given options.
func (r *runnerImpl) createLimiter(rate int, opts ...Option) Limiter {
func (r *runnerImpl) createLimiter(rate int64, opts ...Option) Limiter {
opts = append(opts, WithClock(r.clock))
return r.constructor(rate, opts...)
}
Expand Down