core: Avoid concurrent map access in TestContext2Apply_multiVar

This commit is contained in:
Martin Atkins 2018-09-06 17:09:01 -07:00
parent 7f1954e70c
commit 972b28745b
1 changed files with 10 additions and 0 deletions

View File

@ -3535,10 +3535,13 @@ func TestContext2Apply_multiVarComprehensive(t *testing.T) {
p := testProvider("test") p := testProvider("test")
configs := map[string]*ResourceConfig{} configs := map[string]*ResourceConfig{}
var configsLock sync.Mutex
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
p.DiffFn = func(info *InstanceInfo, s *InstanceState, c *ResourceConfig) (*InstanceDiff, error) { p.DiffFn = func(info *InstanceInfo, s *InstanceState, c *ResourceConfig) (*InstanceDiff, error) {
configsLock.Lock()
defer configsLock.Unlock()
configs[info.HumanId()] = c configs[info.HumanId()] = c
// Return a minimal diff to make sure this resource gets included in // Return a minimal diff to make sure this resource gets included in
@ -3599,6 +3602,13 @@ func TestContext2Apply_multiVarComprehensive(t *testing.T) {
} }
checkConfig := func(name string, want map[string]interface{}) { checkConfig := func(name string, want map[string]interface{}) {
configsLock.Lock()
defer configsLock.Unlock()
if _, ok := configs[name]; !ok {
t.Errorf("no config recorded for %s; expected a configuration", name)
return
}
got := configs[name].Config got := configs[name].Config
t.Run("config for "+name, func(t *testing.T) { t.Run("config for "+name, func(t *testing.T) {
for _, problem := range deep.Equal(got, want) { for _, problem := range deep.Equal(got, want) {