Skip to content

Commit

Permalink
fix flakieness
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxinyi7 committed Feb 21, 2023
1 parent 8e5942f commit bb33b60
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions test/integration/consul-container/test/ratelimit/ratelimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestServerRequestRateLimit(t *testing.T) {
description string
cmd string
operations []operation
mode string
}

getKV := action{
Expand All @@ -70,6 +71,7 @@ func TestServerRequestRateLimit(t *testing.T) {
{
description: "HTTP & net/RPC / Mode: disabled - errors: no / exceeded logs: no / metrics: no",
cmd: `-hcl=limits { request_limits { mode = "disabled" read_rate = 0 write_rate = 0 }}`,
mode: "disabled",
operations: []operation{
{
action: putKV,
Expand All @@ -88,6 +90,7 @@ func TestServerRequestRateLimit(t *testing.T) {
{
description: "HTTP & net/RPC / Mode: permissive - errors: no / exceeded logs: yes / metrics: yes",
cmd: `-hcl=limits { request_limits { mode = "permissive" read_rate = 0 write_rate = 0 }}`,
mode: "permissive",
operations: []operation{
{
action: putKV,
Expand All @@ -106,6 +109,7 @@ func TestServerRequestRateLimit(t *testing.T) {
{
description: "HTTP & net/RPC / Mode: enforcing - errors: yes / exceeded logs: yes / metrics: yes",
cmd: `-hcl=limits { request_limits { mode = "enforcing" read_rate = 0 write_rate = 0 }}`,
mode: "enforcing",
operations: []operation{
{
action: putKV,
Expand Down Expand Up @@ -154,7 +158,7 @@ func TestServerRequestRateLimit(t *testing.T) {
// require.NoError(t, err)
if metricsInfo != nil && err == nil {
if op.expectMetric {
checkForMetric(r, metricsInfo, op.action.rateLimitOperation, op.action.rateLimitType)
checkForMetric(r, metricsInfo, op.action.rateLimitOperation, op.action.rateLimitType, tc.mode)
}
}

Expand All @@ -171,17 +175,17 @@ func TestServerRequestRateLimit(t *testing.T) {
}
}

func checkForMetric(t *retry.R, metricsInfo *api.MetricsInfo, operationName string, expectedLimitType string) {
const counterName = "rpc.rate_limit.exceeded"
func checkForMetric(t *retry.R, metricsInfo *api.MetricsInfo, operationName string, expectedLimitType string, expectedMode string) {
const counterName = "consul.rpc.rate_limit.exceeded"

var counter api.SampledValue
for _, c := range metricsInfo.Counters {
if counter.Name == counterName {
if c.Name == counterName {
counter = c
break
}
}
require.NotNilf(t, counter, "counter not found: %s", counterName)
require.NotEmptyf(t, counter.Name, "counter not found: %s", counterName)

operation, ok := counter.Labels["op"]
require.True(t, ok)
Expand All @@ -193,9 +197,9 @@ func checkForMetric(t *retry.R, metricsInfo *api.MetricsInfo, operationName stri
require.True(t, ok)

if operation == operationName {
require.Equal(t, 2, counter.Count)
require.GreaterOrEqual(t, counter.Count, 1)
require.Equal(t, expectedLimitType, limitType)
require.Equal(t, "disabled", mode)
require.Equal(t, expectedMode, mode)
}
}

Expand Down

0 comments on commit bb33b60

Please sign in to comment.