@@ -38,24 +38,25 @@ func TestPushRequestRateLimit(t *testing.T) {
3838 maxReq := int64 (2 )
3939 duration := 60 * time .Second
4040
41- for i := 0 ; i < 4 ; i ++ {
41+ for i := range 4 {
4242 normalCount , overCount , _ := rl .PushRequest (maxReq , duration , 1 , "group1" , "model1" )
4343
44- if i < 2 {
44+ switch {
45+ case i < 2 :
4546 if normalCount != int64 (i + 1 ) {
4647 t .Errorf ("Request %d: expected normalCount %d, got %d" , i + 1 , i + 1 , normalCount )
4748 }
4849 if overCount != 0 {
4950 t .Errorf ("Request %d: expected overCount 0, got %d" , i + 1 , overCount )
5051 }
51- } else if i == 2 {
52+ case i == 2 :
5253 if normalCount != 3 {
5354 t .Errorf ("Request %d: expected normalCount 3, got %d" , i + 1 , normalCount )
5455 }
5556 if overCount != 0 {
5657 t .Errorf ("Request %d: expected overCount 0, got %d" , i + 1 , overCount )
5758 }
58- } else {
59+ case i == 3 :
5960 if normalCount != 3 {
6061 t .Errorf ("Request %d: expected normalCount 3, got %d" , i + 1 , normalCount )
6162 }
@@ -69,7 +70,7 @@ func TestPushRequestRateLimit(t *testing.T) {
6970func TestPushRequestUnlimited (t * testing.T ) {
7071 rl := reqlimit .NewInMemoryRecord ()
7172
72- for i := 0 ; i < 5 ; i ++ {
73+ for i := range 5 {
7374 normalCount , overCount , _ := rl .PushRequest (0 , 60 * time .Second , 1 , "group1" , "model1" )
7475
7576 if normalCount != int64 (i + 1 ) {
@@ -153,8 +154,8 @@ func TestConcurrentAccess(t *testing.T) {
153154 var wg sync.WaitGroup
154155 wg .Add (numGoroutines )
155156
156- for i := 0 ; i < numGoroutines ; i ++ {
157- go func (id int ) {
157+ for i := range numGoroutines {
158+ go func (_ int ) {
158159 defer wg .Done ()
159160 for j := 0 ; j < requestsPerGoroutine ; j ++ {
160161 rl .PushRequest (0 , 60 * time .Second , 1 , "group1" , "model1" )
@@ -178,7 +179,7 @@ func TestConcurrentDifferentKeys(t *testing.T) {
178179 var wg sync.WaitGroup
179180 wg .Add (numGoroutines )
180181
181- for i := 0 ; i < numGoroutines ; i ++ {
182+ for i := range numGoroutines {
182183 go func (id int ) {
183184 defer wg .Done ()
184185 group := fmt .Sprintf ("group%d" , id % 5 )
@@ -202,7 +203,7 @@ func TestRateLimitWithOverflow(t *testing.T) {
202203 maxReq := 5
203204 duration := 60 * time .Second
204205
205- for i := 0 ; i < 10 ; i ++ {
206+ for i := range 10 {
206207 normalCount , overCount , _ := rl .PushRequest (int64 (maxReq ), duration , 1 , "group1" , "model1" )
207208
208209 if i < maxReq {
@@ -252,7 +253,7 @@ func BenchmarkPushRequest(b *testing.B) {
252253func BenchmarkGetRequest (b * testing.B ) {
253254 rl := reqlimit .NewInMemoryRecord ()
254255
255- for i := 0 ; i < 100 ; i ++ {
256+ for i := range 100 {
256257 group := fmt .Sprintf ("group%d" , i % 10 )
257258 model := fmt .Sprintf ("model%d" , i % 5 )
258259 rl .PushRequest (100 , 60 * time .Second , 1 , group , model )
0 commit comments