Skip to content

Commit

Permalink
Merge pull request #9460 from hashicorp/dnephin/fix-data-races
Browse files Browse the repository at this point in the history
Fix a couple data races in tests
  • Loading branch information
dnephin authored Jan 14, 2021
2 parents 6bf49d7 + 71b82a7 commit 8fdc789
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
12 changes: 6 additions & 6 deletions agent/consul/leader_connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions agent/consul/stats_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 8fdc789

Please sign in to comment.