From 972b28745b99b9673dd9eee40d1250defd6a8148 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 6 Sep 2018 17:09:01 -0700 Subject: [PATCH] core: Avoid concurrent map access in TestContext2Apply_multiVar --- terraform/context_apply_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 1741a9fa7..f0e98cd52 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -3535,10 +3535,13 @@ func TestContext2Apply_multiVarComprehensive(t *testing.T) { p := testProvider("test") configs := map[string]*ResourceConfig{} + var configsLock sync.Mutex p.ApplyFn = testApplyFn p.DiffFn = func(info *InstanceInfo, s *InstanceState, c *ResourceConfig) (*InstanceDiff, error) { + configsLock.Lock() + defer configsLock.Unlock() configs[info.HumanId()] = c // 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{}) { + 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 t.Run("config for "+name, func(t *testing.T) { for _, problem := range deep.Equal(got, want) {