From bae9125fc163d62804eb7115b3dec855e273e4d0 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 22 Dec 2020 18:27:18 -0500 Subject: [PATCH 1/2] Fix one race caused by t.Parallel --- agent/consul/leader_connect_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/agent/consul/leader_connect_test.go b/agent/consul/leader_connect_test.go index ba7122911f..9fd7816014 100644 --- a/agent/consul/leader_connect_test.go +++ b/agent/consul/leader_connect_test.go @@ -12,16 +12,17 @@ import ( "testing" "time" + uuid "github.com/hashicorp/go-uuid" + msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/hashicorp/consul/agent/connect" "github.com/hashicorp/consul/agent/connect/ca" "github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/agent/token" "github.com/hashicorp/consul/sdk/testutil/retry" "github.com/hashicorp/consul/testrpc" - uuid "github.com/hashicorp/go-uuid" - msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestLeader_SecondaryCA_Initialize(t *testing.T) { @@ -923,8 +924,7 @@ func TestLeader_CARootPruning(t *testing.T) { t.Skip("too slow for testing.Short") } - t.Parallel() - + // Can not use t.Parallel(), because this modifies a global. caRootPruneInterval = 200 * time.Millisecond require := require.New(t) From 71b82a7e5bc3b087b59943a52d98b50f1e91f8be Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 22 Dec 2020 18:53:54 -0500 Subject: [PATCH 2/2] Maybe fix another data race in a test --- agent/consul/stats_fetcher_test.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/agent/consul/stats_fetcher_test.go b/agent/consul/stats_fetcher_test.go index 5afd928ce5..018f3ccc91 100644 --- a/agent/consul/stats_fetcher_test.go +++ b/agent/consul/stats_fetcher_test.go @@ -6,11 +6,12 @@ import ( "testing" "time" + "github.com/hashicorp/raft" + "github.com/hashicorp/consul/agent/metadata" "github.com/hashicorp/consul/sdk/testutil/retry" "github.com/hashicorp/consul/testrpc" "github.com/hashicorp/consul/types" - "github.com/hashicorp/raft" ) func TestStatsFetcher(t *testing.T) { @@ -76,8 +77,14 @@ func TestStatsFetcher(t *testing.T) { // from it. func() { retry.Run(t, func(r *retry.R) { + s1.statsFetcher.inflightLock.Lock() s1.statsFetcher.inflight[raft.ServerID(s3.config.NodeID)] = struct{}{} - defer delete(s1.statsFetcher.inflight, raft.ServerID(s3.config.NodeID)) + s1.statsFetcher.inflightLock.Unlock() + defer func() { + s1.statsFetcher.inflightLock.Lock() + delete(s1.statsFetcher.inflight, raft.ServerID(s3.config.NodeID)) + s1.statsFetcher.inflightLock.Unlock() + }() ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel()