-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix various flaky tests #16396
Fix various flaky tests #16396
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ import ( | |
|
||
"github.com/armon/go-metrics" | ||
envoy_discovery_v3 "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3" | ||
"github.com/hashicorp/consul/api" | ||
"github.com/stretchr/testify/require" | ||
rpcstatus "google.golang.org/genproto/googleapis/rpc/status" | ||
"google.golang.org/grpc/codes" | ||
|
@@ -21,8 +20,10 @@ import ( | |
"github.com/hashicorp/consul/agent/grpc-external/limiter" | ||
"github.com/hashicorp/consul/agent/proxycfg" | ||
"github.com/hashicorp/consul/agent/structs" | ||
"github.com/hashicorp/consul/api" | ||
"github.com/hashicorp/consul/envoyextensions/xdscommon" | ||
"github.com/hashicorp/consul/sdk/testutil" | ||
"github.com/hashicorp/consul/sdk/testutil/retry" | ||
"github.com/hashicorp/consul/version" | ||
) | ||
|
||
|
@@ -1057,19 +1058,23 @@ func TestServer_DeltaAggregatedResources_v3_ACLEnforcement(t *testing.T) { | |
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
// aclResolve may be called in a goroutine even after a | ||
// testcase tt returns. Capture the variable as tc so the | ||
// values don't swap in the next iteration. | ||
tc := tt | ||
aclResolve := func(id string) (acl.Authorizer, error) { | ||
if !tt.defaultDeny { | ||
if !tc.defaultDeny { | ||
// Allow all | ||
return acl.RootAuthorizer("allow"), nil | ||
} | ||
if tt.acl == "" { | ||
if tc.acl == "" { | ||
// No token and defaultDeny is denied | ||
return acl.RootAuthorizer("deny"), nil | ||
} | ||
// Ensure the correct token was passed | ||
require.Equal(t, tt.token, id) | ||
require.Equal(t, tc.token, id) | ||
// Parse the ACL and enforce it | ||
policy, err := acl.NewPolicyFromSource(tt.acl, nil, nil) | ||
policy, err := acl.NewPolicyFromSource(tc.acl, nil, nil) | ||
require.NoError(t, err) | ||
return acl.NewPolicyAuthorizerWithDefaults(acl.RootAuthorizer("deny"), []*acl.Policy{policy}, nil) | ||
} | ||
|
@@ -1095,13 +1100,15 @@ func TestServer_DeltaAggregatedResources_v3_ACLEnforcement(t *testing.T) { | |
|
||
// If there is no token, check that we increment the gauge | ||
if tt.token == "" { | ||
data := scenario.sink.Data() | ||
require.Len(t, data, 1) | ||
|
||
item := data[0] | ||
val, ok := item.Gauges["consul.xds.test.xds.server.streamsUnauthenticated"] | ||
require.True(t, ok) | ||
require.Equal(t, float32(1), val.Value) | ||
retry.Run(t, func(r *retry.R) { | ||
data := scenario.sink.Data() | ||
require.Len(r, data, 1) | ||
|
||
item := data[0] | ||
val, ok := item.Gauges["consul.xds.test.xds.server.streamsUnauthenticated"] | ||
require.True(r, ok) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assertion was failing randomly; I'm not 100% confident this will fix the issue but since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the retry might fix the issue. When reading this code earlier, I assumed this assertion was failing randomly because this key
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The gauge should be incremented in a normal codepath that is taken during the test: 1, 2 I think the tests could be flaking because either:
I didn't spend too much time looking into it but added a bunch of fixes for possible culprits |
||
require.Equal(r, float32(1), val.Value) | ||
}) | ||
} | ||
|
||
if !tt.wantDenied { | ||
|
@@ -1138,13 +1145,15 @@ func TestServer_DeltaAggregatedResources_v3_ACLEnforcement(t *testing.T) { | |
|
||
// If there is no token, check that we decrement the gauge | ||
if tt.token == "" { | ||
data := scenario.sink.Data() | ||
require.Len(t, data, 1) | ||
|
||
item := data[0] | ||
val, ok := item.Gauges["consul.xds.test.xds.server.streamsUnauthenticated"] | ||
require.True(t, ok) | ||
require.Equal(t, float32(0), val.Value) | ||
retry.Run(t, func(r *retry.R) { | ||
data := scenario.sink.Data() | ||
require.Len(r, data, 1) | ||
|
||
item := data[0] | ||
val, ok := item.Gauges["consul.xds.test.xds.server.streamsUnauthenticated"] | ||
require.True(r, ok) | ||
require.Equal(r, float32(0), val.Value) | ||
}) | ||
} | ||
}) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,9 +166,6 @@ func newTestServerDeltaScenario( | |
) *testServerScenario { | ||
mgr := newTestManager(t) | ||
envoy := NewTestEnvoy(t, proxyID, token) | ||
t.Cleanup(func() { | ||
envoy.Close() | ||
}) | ||
Comment on lines
-169
to
-171
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cleanups and defers are run in LIFO order. I wanted to ensure |
||
|
||
sink := metrics.NewInmemSink(1*time.Minute, 1*time.Minute) | ||
cfg := metrics.DefaultConfig("consul.xds.test") | ||
|
@@ -177,6 +174,7 @@ func newTestServerDeltaScenario( | |
metrics.NewGlobal(cfg, sink) | ||
|
||
t.Cleanup(func() { | ||
envoy.Close() | ||
sink := &metrics.BlackholeSink{} | ||
metrics.NewGlobal(cfg, sink) | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -270,7 +270,8 @@ func (c *cmd) prepare() (version string, err error) { | |
// If none are specified we will collect information from | ||
// all by default | ||
if len(c.capture) == 0 { | ||
c.capture = defaultTargets | ||
c.capture = make([]string, len(defaultTargets)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. very fun slice debugging exercise where the code block below was mutating |
||
copy(c.capture, defaultTargets) | ||
} | ||
|
||
// If EnableDebug is not true, skip collecting pprof | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
incrementalTime
it
was being modified in a goroutine so there was a data race, leadingdisconnectTime
to be sometimes incorrectly early. I moved the call to be local to each retry loop so that it would fetch the latest "now" value instead of predicting it would be 1 second in the future.