forked from argoproj/argo-cd
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c4c089
commit 21e6fed
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
### Event reporter v2.0.3 | ||
1. Implemented a fixed window rate limiter for the event reporter to prevent the application from overflowing the entire reporter queue. This enhancement ensures timely reporting without causing delays for other applications. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package reporter | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestRateLimiter(t *testing.T) { | ||
t.Run("Limiter is turned off", func(t *testing.T) { | ||
rl := NewRateLimiter(&RateLimiterOpts{ | ||
Enabled: false, | ||
}) | ||
d, err := rl.Limit("foo") | ||
if err != nil { | ||
t.Errorf("Expected no error, got %v", err) | ||
} | ||
if d != 0 { | ||
t.Errorf("Expected 0 duration, got %v", d) | ||
} | ||
}) | ||
t.Run("Limiter is turned on", func(t *testing.T) { | ||
rl := NewRateLimiter(&RateLimiterOpts{ | ||
Enabled: true, | ||
Rate: time.Second, | ||
Capacity: 1, | ||
}) | ||
d, err := rl.Limit("foo") | ||
if err != nil { | ||
t.Errorf("Expected no error, got %v", err) | ||
} | ||
if d != 0 { | ||
t.Errorf("Expected 0 duration, got %v", d) | ||
} | ||
}) | ||
t.Run("Limiter is turned on but with 0 capacity", func(t *testing.T) { | ||
rl := NewRateLimiter(&RateLimiterOpts{ | ||
Enabled: true, | ||
Rate: time.Second, | ||
Capacity: 0, | ||
}) | ||
_, err := rl.Limit("foo") | ||
if err == nil { | ||
t.Errorf("Expected error, got nil") | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters