Skip to content

Commit 986b410

Browse files
committed
Tweak API
1 parent e88af69 commit 986b410

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

rate.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ func (l *Limiter) AllowN(
101101
return res, nil
102102
}
103103

104-
// AllowAtMostN reports whether at most n events may happen at time now.
104+
// AllowAtMost reports whether at most n events may happen at time now.
105105
// It returns number of allowed events that is less than or equal to n.
106-
func (l *Limiter) AllowAtMostN(
106+
func (l *Limiter) AllowAtMost(
107107
ctx context.Context,
108108
key string,
109109
limit *Limit,

rate_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestAllow(t *testing.T) {
5656
assert.InDelta(t, res.ResetAfter, 999*time.Millisecond, float64(10*time.Millisecond))
5757
}
5858

59-
func TestAllowAtMostN(t *testing.T) {
59+
func TestAllowAtMost(t *testing.T) {
6060
ctx := context.Background()
6161

6262
l := rateLimiter()
@@ -69,7 +69,7 @@ func TestAllowAtMostN(t *testing.T) {
6969
assert.Equal(t, res.RetryAfter, time.Duration(-1))
7070
assert.InDelta(t, res.ResetAfter, 100*time.Millisecond, float64(10*time.Millisecond))
7171

72-
res, err = l.AllowAtMostN(ctx, "test_id", limit, 2)
72+
res, err = l.AllowAtMost(ctx, "test_id", limit, 2)
7373
assert.Nil(t, err)
7474
assert.Equal(t, res.Allowed, 2)
7575
assert.Equal(t, res.Remaining, 7)
@@ -83,7 +83,7 @@ func TestAllowAtMostN(t *testing.T) {
8383
assert.Equal(t, res.RetryAfter, time.Duration(-1))
8484
assert.InDelta(t, res.ResetAfter, 300*time.Millisecond, float64(10*time.Millisecond))
8585

86-
res, err = l.AllowAtMostN(ctx, "test_id", limit, 10)
86+
res, err = l.AllowAtMost(ctx, "test_id", limit, 10)
8787
assert.Nil(t, err)
8888
assert.Equal(t, res.Allowed, 7)
8989
assert.Equal(t, res.Remaining, 0)
@@ -97,7 +97,7 @@ func TestAllowAtMostN(t *testing.T) {
9797
assert.Equal(t, res.RetryAfter, time.Duration(-1))
9898
assert.InDelta(t, res.ResetAfter, 999*time.Millisecond, float64(10*time.Millisecond))
9999

100-
res, err = l.AllowAtMostN(ctx, "test_id", limit, 1000)
100+
res, err = l.AllowAtMost(ctx, "test_id", limit, 1000)
101101
assert.Nil(t, err)
102102
assert.Equal(t, res.Allowed, 0)
103103
assert.Equal(t, res.Remaining, 0)
@@ -132,7 +132,7 @@ func BenchmarkAllow(b *testing.B) {
132132
})
133133
}
134134

135-
func BenchmarkAllowAtMostN(b *testing.B) {
135+
func BenchmarkAllowAtMost(b *testing.B) {
136136
ctx := context.Background()
137137
l := rateLimiter()
138138
limit := redis_rate.PerSecond(1e6)
@@ -141,7 +141,7 @@ func BenchmarkAllowAtMostN(b *testing.B) {
141141

142142
b.RunParallel(func(pb *testing.PB) {
143143
for pb.Next() {
144-
res, err := l.AllowAtMostN(ctx, "foo", limit, 1)
144+
res, err := l.AllowAtMost(ctx, "foo", limit, 1)
145145
if err != nil {
146146
b.Fatal(err)
147147
}

0 commit comments

Comments
 (0)