Merge pull request #1069 from hashicorp/b-tainted-double-destroy

core: band-aid fix for tainted double destroy
This commit is contained in:
Mitchell Hashimoto 2015-02-26 23:50:56 -08:00
commit 06d1a242d2
2 changed files with 32 additions and 9 deletions

View File

@ -8,7 +8,9 @@ import (
"sort" "sort"
"strings" "strings"
"sync" "sync"
"sync/atomic"
"testing" "testing"
"time"
) )
func TestContext2Plan(t *testing.T) { func TestContext2Plan(t *testing.T) {
@ -4646,7 +4648,22 @@ func TestContext2Apply_outputMultiIndex(t *testing.T) {
func TestContext2Apply_taint(t *testing.T) { func TestContext2Apply_taint(t *testing.T) {
m := testModule(t, "apply-taint") m := testModule(t, "apply-taint")
p := testProvider("aws") p := testProvider("aws")
p.ApplyFn = testApplyFn
// destroyCount tests against regression of
// https://github.com/hashicorp/terraform/issues/1056
var destroyCount = int32(0)
var once sync.Once
simulateProviderDelay := func() {
time.Sleep(10 * time.Millisecond)
}
p.ApplyFn = func(info *InstanceInfo, s *InstanceState, d *InstanceDiff) (*InstanceState, error) {
once.Do(simulateProviderDelay)
if d.Destroy {
atomic.AddInt32(&destroyCount, 1)
}
return testApplyFn(info, s, d)
}
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
s := &State{ s := &State{
Modules: []*ModuleState{ Modules: []*ModuleState{
@ -4691,6 +4708,10 @@ func TestContext2Apply_taint(t *testing.T) {
if actual != expected { if actual != expected {
t.Fatalf("bad:\n%s", actual) t.Fatalf("bad:\n%s", actual)
} }
if destroyCount != 1 {
t.Fatalf("Expected 1 destroy, got %d", destroyCount)
}
} }
func TestContext2Apply_unknownAttribute(t *testing.T) { func TestContext2Apply_unknownAttribute(t *testing.T) {

View File

@ -293,14 +293,16 @@ func (n *GraphNodeConfigResource) DynamicExpand(ctx EvalContext) (*Graph, error)
View: n.Resource.Id(), View: n.Resource.Id(),
}) })
// If we're only destroying tainted resources, then we only if n.Resource.Lifecycle.CreateBeforeDestroy {
// want to find tainted resources and destroy them here. // If we're only destroying tainted resources, then we only
steps = append(steps, &TaintedTransformer{ // want to find tainted resources and destroy them here.
State: state, steps = append(steps, &TaintedTransformer{
View: n.Resource.Id(), State: state,
Deposed: n.Resource.Lifecycle.CreateBeforeDestroy, View: n.Resource.Id(),
DeposedInclude: true, Deposed: n.Resource.Lifecycle.CreateBeforeDestroy,
}) DeposedInclude: true,
})
}
case DestroyTainted: case DestroyTainted:
// If we're only destroying tainted resources, then we only // If we're only destroying tainted resources, then we only
// want to find tainted resources and destroy them here. // want to find tainted resources and destroy them here.