Skip to content

Commit 7590ca3

Browse files
triaging concurrent map access
Signed-off-by: Vasundhara Shukla <vasundharas@vmware.com>
1 parent cee6935 commit 7590ca3

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

examples/usecases/usecase1.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,4 @@ output "attach_output" {
144144

145145
output "display_cluster" {
146146
value = tmc_cluster.create_tkgs_workload
147-
}
147+
}

internal/client/transport/methods.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (c *Client) invokeAction(httpMethodType string, url string, request Request
4141
return errors.Wrap(err, "marshall request body")
4242
}
4343

44-
headers := c.Headers
44+
headers := c.Headers.Clone()
4545
headers.Set(contentLengthKey, fmt.Sprintf("%d", len(body)))
4646

4747
var resp *http.Response
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
Copyright © 2021 VMware, Inc. All Rights Reserved.
3+
SPDX-License-Identifier: MPL-2.0
4+
*/
5+
6+
package transport
7+
8+
import (
9+
"sync"
10+
"testing"
11+
12+
"github.com/stretchr/testify/require"
13+
14+
workspacemodel "github.com/vmware-tanzu/terraform-provider-tanzu-mission-control/internal/models/workspace"
15+
)
16+
17+
type Invoke struct {
18+
HTTPMethodType string
19+
URL string
20+
Request Request
21+
Response Response
22+
}
23+
24+
func TestConcurrentAccessOfInvokeAction(t *testing.T) {
25+
var input Invoke
26+
27+
var waitGroup sync.WaitGroup
28+
29+
input.HTTPMethodType = "POST"
30+
input.URL = "xyz.com"
31+
input.Request = &workspacemodel.VmwareTanzuManageV1alpha1WorkspaceRequest{
32+
Workspace: &workspacemodel.VmwareTanzuManageV1alpha1WorkspaceWorkspace{
33+
FullName: &workspacemodel.VmwareTanzuManageV1alpha1WorkspaceFullName{
34+
Name: "tf-workspace-test",
35+
},
36+
},
37+
}
38+
input.Response = &workspacemodel.VmwareTanzuManageV1alphaWorkspaceResponse{
39+
Workspace: &workspacemodel.VmwareTanzuManageV1alpha1WorkspaceWorkspace{
40+
FullName: &workspacemodel.VmwareTanzuManageV1alpha1WorkspaceFullName{
41+
Name: "tf-workspace-test",
42+
},
43+
},
44+
}
45+
46+
c := NewClient()
47+
c.AddHeaders(map[string][]string{
48+
"header1": {"one", "two"},
49+
"header2": {"three", "four"},
50+
})
51+
52+
for i := 1; i <= 100; i++ {
53+
waitGroup.Add(1)
54+
55+
go func() {
56+
defer waitGroup.Done()
57+
58+
actual := c.invokeAction(input.HTTPMethodType, input.URL, input.Request, input.Response)
59+
require.Error(t, actual)
60+
}()
61+
}
62+
waitGroup.Wait()
63+
}

internal/resources/cluster/manifest/helper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2020 VMware, Inc. All rights reserved.
2+
Copyright (c) 2021 VMware, Inc. All rights reserved.
33
44
Proprietary and confidential.
55

0 commit comments

Comments
 (0)