| 1 |
Description: Fix tests failing on 32bit arches |
| 2 |
Author: Aloïs Micard <[email protected]> |
| 3 |
Reviewed-by: Aloïs Micard <[email protected]> |
| 4 |
Last-Update: 2024-09-01 |
| 5 |
Forwarded: https://github.com/uber-go/ratelimit/pull/129 |
| 6 |
|
| 7 |
--- a/limiter_atomic.go |
| 8 |
+++ b/limiter_atomic.go |
| 9 |
@@ -44,7 +44,7 @@ |
| 10 |
} |
| 11 |
|
| 12 |
// newAtomicBased returns a new atomic based limiter. |
| 13 |
-func newAtomicBased(rate int, opts ...Option) *atomicLimiter { |
| 14 |
+func newAtomicBased(rate int64, opts ...Option) *atomicLimiter { |
| 15 |
// TODO consider moving config building to the implementation |
| 16 |
// independent code. |
| 17 |
config := buildConfig(opts) |
| 18 |
--- a/limiter_atomic_int64.go |
| 19 |
+++ b/limiter_atomic_int64.go |
| 20 |
@@ -39,7 +39,7 @@ |
| 21 |
} |
| 22 |
|
| 23 |
// newAtomicBased returns a new atomic based limiter. |
| 24 |
-func newAtomicInt64Based(rate int, opts ...Option) *atomicInt64Limiter { |
| 25 |
+func newAtomicInt64Based(rate int64, opts ...Option) *atomicInt64Limiter { |
| 26 |
// TODO consider moving config building to the implementation |
| 27 |
// independent code. |
| 28 |
config := buildConfig(opts) |
| 29 |
--- a/limiter_mutexbased.go |
| 30 |
+++ b/limiter_mutexbased.go |
| 31 |
@@ -35,7 +35,7 @@ |
| 32 |
} |
| 33 |
|
| 34 |
// newMutexBased returns a new mutex based limiter. |
| 35 |
-func newMutexBased(rate int, opts ...Option) *mutexLimiter { |
| 36 |
+func newMutexBased(rate int64, opts ...Option) *mutexLimiter { |
| 37 |
// TODO consider moving config building to the implementation |
| 38 |
// independent code. |
| 39 |
config := buildConfig(opts) |
| 40 |
--- a/ratelimit_test.go |
| 41 |
+++ b/ratelimit_test.go |
| 42 |
@@ -13,7 +13,7 @@ |
| 43 |
|
| 44 |
type testRunner interface { |
| 45 |
// createLimiter builds a limiter with given options. |
| 46 |
- createLimiter(int, ...Option) Limiter |
| 47 |
+ createLimiter(int64, ...Option) Limiter |
| 48 |
// takeOnceAfter attempts to Take at a specific time. |
| 49 |
takeOnceAfter(time.Duration, Limiter) |
| 50 |
// startTaking tries to Take() on passed in limiters in a loop/goroutine. |
| 51 |
@@ -32,7 +32,7 @@ |
| 52 |
t *testing.T |
| 53 |
|
| 54 |
clock *clock.Mock |
| 55 |
- constructor func(int, ...Option) Limiter |
| 56 |
+ constructor func(int64, ...Option) Limiter |
| 57 |
count atomic.Int32 |
| 58 |
// maxDuration is the time we need to move into the future for a test. |
| 59 |
// It's populated automatically based on assertCountAt/afterFunc. |
| 60 |
@@ -44,23 +44,23 @@ |
| 61 |
func runTest(t *testing.T, fn func(testRunner)) { |
| 62 |
impls := []struct { |
| 63 |
name string |
| 64 |
- constructor func(int, ...Option) Limiter |
| 65 |
+ constructor func(int64, ...Option) Limiter |
| 66 |
}{ |
| 67 |
{ |
| 68 |
name: "mutex", |
| 69 |
- constructor: func(rate int, opts ...Option) Limiter { |
| 70 |
+ constructor: func(rate int64, opts ...Option) Limiter { |
| 71 |
return newMutexBased(rate, opts...) |
| 72 |
}, |
| 73 |
}, |
| 74 |
{ |
| 75 |
name: "atomic", |
| 76 |
- constructor: func(rate int, opts ...Option) Limiter { |
| 77 |
+ constructor: func(rate int64, opts ...Option) Limiter { |
| 78 |
return newAtomicBased(rate, opts...) |
| 79 |
}, |
| 80 |
}, |
| 81 |
{ |
| 82 |
name: "atomic_int64", |
| 83 |
- constructor: func(rate int, opts ...Option) Limiter { |
| 84 |
+ constructor: func(rate int64, opts ...Option) Limiter { |
| 85 |
return newAtomicInt64Based(rate, opts...) |
| 86 |
}, |
| 87 |
}, |
| 88 |
@@ -88,7 +88,7 @@ |
| 89 |
} |
| 90 |
|
| 91 |
// createLimiter builds a limiter with given options. |
| 92 |
-func (r *runnerImpl) createLimiter(rate int, opts ...Option) Limiter { |
| 93 |
+func (r *runnerImpl) createLimiter(rate int64, opts ...Option) Limiter { |
| 94 |
opts = append(opts, WithClock(r.clock)) |
| 95 |
return r.constructor(rate, opts...) |
| 96 |
} |
| 97 |
--- a/ratelimit_bench_test.go |
| 98 |
+++ b/ratelimit_bench_test.go |
| 99 |
@@ -14,9 +14,9 @@ |
| 100 |
for _, procs := range []int{1, 4, 8, 16} { |
| 101 |
runtime.GOMAXPROCS(procs) |
| 102 |
for name, limiter := range map[string]Limiter{ |
| 103 |
- "atomic": newAtomicBased(b.N * 1000000000000), |
| 104 |
- "atomic_int64": newAtomicInt64Based(b.N * 1000000000000), |
| 105 |
- "mutex": newMutexBased(b.N * 1000000000000), |
| 106 |
+ "atomic": newAtomicBased(int64(b.N) * int64(1000000000000)), |
| 107 |
+ "atomic_int64": newAtomicInt64Based(int64(b.N) * int64(1000000000000)), |
| 108 |
+ "mutex": newMutexBased(int64(b.N) * int64(1000000000000)), |
| 109 |
} { |
| 110 |
for ng := 1; ng < 16; ng++ { |
| 111 |
runner(b, name, procs, ng, limiter, count) |
| 112 |
--- a/ratelimit.go |
| 113 |
+++ b/ratelimit.go |
| 114 |
@@ -53,7 +53,7 @@ |
| 115 |
} |
| 116 |
|
| 117 |
// New returns a Limiter that will limit to the given RPS. |
| 118 |
-func New(rate int, opts ...Option) Limiter { |
| 119 |
+func New(rate int64, opts ...Option) Limiter { |
| 120 |
return newAtomicInt64Based(rate, opts...) |
| 121 |
} |
| 122 |
|