mirror of
https://github.com/status-im/consul.git
synced 2025-01-12 14:55:02 +00:00
fix flakieness (#16338)
This commit is contained in:
parent
8e5942f5ca
commit
9d55cd1f18
@ -46,6 +46,7 @@ func TestServerRequestRateLimit(t *testing.T) {
|
|||||||
description string
|
description string
|
||||||
cmd string
|
cmd string
|
||||||
operations []operation
|
operations []operation
|
||||||
|
mode string
|
||||||
}
|
}
|
||||||
|
|
||||||
getKV := action{
|
getKV := action{
|
||||||
@ -70,6 +71,7 @@ func TestServerRequestRateLimit(t *testing.T) {
|
|||||||
{
|
{
|
||||||
description: "HTTP & net/RPC / Mode: disabled - errors: no / exceeded logs: no / metrics: no",
|
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 }}`,
|
cmd: `-hcl=limits { request_limits { mode = "disabled" read_rate = 0 write_rate = 0 }}`,
|
||||||
|
mode: "disabled",
|
||||||
operations: []operation{
|
operations: []operation{
|
||||||
{
|
{
|
||||||
action: putKV,
|
action: putKV,
|
||||||
@ -88,6 +90,7 @@ func TestServerRequestRateLimit(t *testing.T) {
|
|||||||
{
|
{
|
||||||
description: "HTTP & net/RPC / Mode: permissive - errors: no / exceeded logs: yes / metrics: yes",
|
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 }}`,
|
cmd: `-hcl=limits { request_limits { mode = "permissive" read_rate = 0 write_rate = 0 }}`,
|
||||||
|
mode: "permissive",
|
||||||
operations: []operation{
|
operations: []operation{
|
||||||
{
|
{
|
||||||
action: putKV,
|
action: putKV,
|
||||||
@ -106,6 +109,7 @@ func TestServerRequestRateLimit(t *testing.T) {
|
|||||||
{
|
{
|
||||||
description: "HTTP & net/RPC / Mode: enforcing - errors: yes / exceeded logs: yes / metrics: yes",
|
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 }}`,
|
cmd: `-hcl=limits { request_limits { mode = "enforcing" read_rate = 0 write_rate = 0 }}`,
|
||||||
|
mode: "enforcing",
|
||||||
operations: []operation{
|
operations: []operation{
|
||||||
{
|
{
|
||||||
action: putKV,
|
action: putKV,
|
||||||
@ -154,7 +158,7 @@ func TestServerRequestRateLimit(t *testing.T) {
|
|||||||
// require.NoError(t, err)
|
// require.NoError(t, err)
|
||||||
if metricsInfo != nil && err == nil {
|
if metricsInfo != nil && err == nil {
|
||||||
if op.expectMetric {
|
if op.expectMetric {
|
||||||
checkForMetric(r, metricsInfo, op.action.rateLimitOperation, op.action.rateLimitType)
|
checkForMetric(r, metricsInfo, op.action.rateLimitOperation, op.action.rateLimitType, tc.mode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,17 +175,17 @@ func TestServerRequestRateLimit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkForMetric(t *retry.R, metricsInfo *api.MetricsInfo, operationName string, expectedLimitType string) {
|
func checkForMetric(t *retry.R, metricsInfo *api.MetricsInfo, operationName string, expectedLimitType string, expectedMode string) {
|
||||||
const counterName = "rpc.rate_limit.exceeded"
|
const counterName = "consul.rpc.rate_limit.exceeded"
|
||||||
|
|
||||||
var counter api.SampledValue
|
var counter api.SampledValue
|
||||||
for _, c := range metricsInfo.Counters {
|
for _, c := range metricsInfo.Counters {
|
||||||
if counter.Name == counterName {
|
if c.Name == counterName {
|
||||||
counter = c
|
counter = c
|
||||||
break
|
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"]
|
operation, ok := counter.Labels["op"]
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
@ -193,9 +197,9 @@ func checkForMetric(t *retry.R, metricsInfo *api.MetricsInfo, operationName stri
|
|||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
|
||||||
if operation == operationName {
|
if operation == operationName {
|
||||||
require.Equal(t, 2, counter.Count)
|
require.GreaterOrEqual(t, counter.Count, 1)
|
||||||
require.Equal(t, expectedLimitType, limitType)
|
require.Equal(t, expectedLimitType, limitType)
|
||||||
require.Equal(t, "disabled", mode)
|
require.Equal(t, expectedMode, mode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user