From d76482cd89928af77384c5a258c0c972021381aa Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 20 Dec 2017 15:51:02 -0500 Subject: [PATCH] don't try to interrupt diff in shutdown test Rather than relying on interrupting Diff, just make sure Stop was called on the provider. The DiffFn is protected by a mutex in the mock provider, which means that the tests can't rely on concurent calls to diff working. --- command/plan_test.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/command/plan_test.go b/command/plan_test.go index 04390ab5bc..3e97fdd476 100644 --- a/command/plan_test.go +++ b/command/plan_test.go @@ -7,7 +7,9 @@ import ( "path/filepath" "reflect" "strings" + "sync" "testing" + "time" "github.com/hashicorp/terraform/helper/copy" "github.com/hashicorp/terraform/terraform" @@ -832,8 +834,7 @@ func TestPlan_detailedExitcode_emptyDiff(t *testing.T) { } func TestPlan_shutdown(t *testing.T) { - cancelled := false - stopped := make(chan struct{}) + cancelled := make(chan struct{}) shutdownCh := make(chan struct{}) p := testProvider() @@ -847,20 +848,20 @@ func TestPlan_shutdown(t *testing.T) { } p.StopFn = func() error { - close(stopped) - cancelled = true + close(cancelled) return nil } + var once sync.Once + p.DiffFn = func( *terraform.InstanceInfo, *terraform.InstanceState, *terraform.ResourceConfig) (*terraform.InstanceDiff, error) { - if !cancelled { + once.Do(func() { shutdownCh <- struct{}{} - <-stopped - } + }) return &terraform.InstanceDiff{ Attributes: map[string]*terraform.ResourceAttrDiff{ @@ -875,7 +876,9 @@ func TestPlan_shutdown(t *testing.T) { t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) } - if !cancelled { + select { + case <-cancelled: + case <-time.After(5 * time.Second): t.Fatal("command not cancelled") } }