Merge pull request #13854 from hashicorp/jbardin/testraces

fix a few races in the context tests
This commit is contained in:
James Bardin 2017-04-21 13:23:12 -04:00 committed by GitHub
commit f4a37ed19a
2 changed files with 14 additions and 0 deletions

View File

@ -4430,6 +4430,7 @@ func TestContext2Apply_provisionerDestroyFailContinue(t *testing.T) {
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
var l sync.Mutex
var calls []string var calls []string
pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error { pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error {
val, ok := c.Config["foo"] val, ok := c.Config["foo"]
@ -4437,6 +4438,8 @@ func TestContext2Apply_provisionerDestroyFailContinue(t *testing.T) {
t.Fatalf("bad value for foo: %v %#v", val, c) t.Fatalf("bad value for foo: %v %#v", val, c)
} }
l.Lock()
defer l.Unlock()
calls = append(calls, val.(string)) calls = append(calls, val.(string))
return fmt.Errorf("provisioner error") return fmt.Errorf("provisioner error")
} }
@ -4501,6 +4504,7 @@ func TestContext2Apply_provisionerDestroyFailContinueFail(t *testing.T) {
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
var l sync.Mutex
var calls []string var calls []string
pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error { pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error {
val, ok := c.Config["foo"] val, ok := c.Config["foo"]
@ -4508,6 +4512,8 @@ func TestContext2Apply_provisionerDestroyFailContinueFail(t *testing.T) {
t.Fatalf("bad value for foo: %v %#v", val, c) t.Fatalf("bad value for foo: %v %#v", val, c)
} }
l.Lock()
defer l.Unlock()
calls = append(calls, val.(string)) calls = append(calls, val.(string))
return fmt.Errorf("provisioner error") return fmt.Errorf("provisioner error")
} }

View File

@ -532,6 +532,9 @@ func TestContext2Plan_moduleProviderInherit(t *testing.T) {
state *InstanceState, state *InstanceState,
c *ResourceConfig) (*InstanceDiff, error) { c *ResourceConfig) (*InstanceDiff, error) {
v, _ := c.Get("from") v, _ := c.Get("from")
l.Lock()
defer l.Unlock()
calls = append(calls, v.(string)) calls = append(calls, v.(string))
return testDiffFn(info, state, c) return testDiffFn(info, state, c)
} }
@ -628,6 +631,9 @@ func TestContext2Plan_moduleProviderDefaults(t *testing.T) {
state *InstanceState, state *InstanceState,
c *ResourceConfig) (*InstanceDiff, error) { c *ResourceConfig) (*InstanceDiff, error) {
v, _ := c.Get("from") v, _ := c.Get("from")
l.Lock()
defer l.Unlock()
calls = append(calls, v.(string)) calls = append(calls, v.(string))
return testDiffFn(info, state, c) return testDiffFn(info, state, c)
} }
@ -677,6 +683,8 @@ func TestContext2Plan_moduleProviderDefaultsVar(t *testing.T) {
buf.WriteString(v.(string) + "\n") buf.WriteString(v.(string) + "\n")
} }
l.Lock()
defer l.Unlock()
calls = append(calls, buf.String()) calls = append(calls, buf.String())
return nil return nil
} }