Skip to content

Commit

Permalink
test(ratelimit_test.go): update CLUSTER_SIZES array to include more v…
Browse files Browse the repository at this point in the history
…alues

test(ratelimit_test.go): adjust test cases in TestRatelimit_Consistency
feat(service.go): increase the number of goroutines for parallel network requests
  • Loading branch information
chronark committed Jul 23, 2024
1 parent 83b8d13 commit f544a5b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
46 changes: 23 additions & 23 deletions apps/agent/services/ratelimit/ratelimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/unkeyed/unkey/apps/agent/services/ratelimit"
)

var CLUSTER_SIZES = []int{20}
var CLUSTER_SIZES = []int{1, 3, 20}

func TestRatelimit_Consistency(t *testing.T) {

Expand All @@ -39,21 +39,21 @@ func TestRatelimit_Consistency(t *testing.T) {
}{
{
name: "Basic Test",
limit: 10,
limit: 100,
duration: 10000,
rps: 15,
seconds: 120,
expectedMin: 120,
expectedMax: 400,
rps: 10,
seconds: 20,
expectedMin: 200,
expectedMax: 200,
},
{
name: "High Rate with Short Window",
limit: 20,
duration: 1000,
rps: 50,
seconds: 60,
expectedMin: 120,
expectedMax: 1200,
limit: 500,
duration: 5000,
rps: 100,
seconds: 10,
expectedMin: 900,
expectedMax: 1000,
},
{
name: "Constant Rate Equals Limit",
Expand All @@ -69,18 +69,18 @@ func TestRatelimit_Consistency(t *testing.T) {
limit: 500,
duration: 10000,
rps: 100,
seconds: 30,
expectedMin: 1500,
expectedMax: 3000,
seconds: 10,
expectedMin: 500,
expectedMax: 1000,
},
{
name: "Rate Higher Than Limit",
limit: 100,
duration: 5000,
rps: 200,
seconds: 120,
expectedMin: 2400,
expectedMax: 3200,
seconds: 15,
expectedMin: 300,
expectedMax: 1500,
},
{
name: "High Burst",
Expand All @@ -94,11 +94,11 @@ func TestRatelimit_Consistency(t *testing.T) {
{
name: "Very Long Window",
limit: 100,
duration: 60000,
rps: 3,
seconds: 120,
expectedMin: 200,
expectedMax: 400,
duration: 120000,
rps: 1,
seconds: 10,
expectedMin: 10,
expectedMax: 10,
},
}

Expand Down
2 changes: 1 addition & 1 deletion apps/agent/services/ratelimit/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func New(cfg Config) (Service, error) {

// Process the individual requests to the origin and update local state
// We're using 8 goroutines to parallelise the network requests'
for range 8 {
for range 32 {
go func() {
for req := range s.syncBuffer {
s.syncWithOrigin(req)
Expand Down

0 comments on commit f544a5b

Please sign in to comment.