Merge pull request #9460 from hashicorp/dnephin/fix-data-races

Fix a couple data races in tests
This commit is contained in:
Daniel Nephin 2021-01-14 17:07:01 -05:00 committed by GitHub
commit 8fdc789ded
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 8 deletions

View File

@ -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)

View File

@ -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()