From 47484e23fe42db36380abbb95a3274e17c4ac610 Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Mon, 21 Aug 2017 19:05:49 -0700 Subject: [PATCH] provisioner/local-exec: Drop untestable error TestResourceProvider_stop uses a goroutine, which means that any function with *testing.T as its receiver within that goroutine will silently fail. Now the test to accepts that an error that occurs within the goroutine is lost. It also adds some more verbose logs to explain what is happening. --- .../local-exec/resource_provisioner_test.go | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/builtin/provisioners/local-exec/resource_provisioner_test.go b/builtin/provisioners/local-exec/resource_provisioner_test.go index 2fa17efc5..cb7dc1c1b 100644 --- a/builtin/provisioners/local-exec/resource_provisioner_test.go +++ b/builtin/provisioners/local-exec/resource_provisioner_test.go @@ -58,26 +58,36 @@ func TestResourceProvider_stop(t *testing.T) { output := new(terraform.MockUIOutput) p := Provisioner() - var err error doneCh := make(chan struct{}) + startTime := time.Now() go func() { defer close(doneCh) - err = p.Apply(output, nil, c) + // The functionality of p.Apply is tested in TestResourceProvider_Apply. + // Because p.Apply is called in a goroutine, trying to t.Fatal() on its + // result would be ignored or would cause a panic if the parent goroutine + // has already completed. + _ = p.Apply(output, nil, c) }() + mustExceed := (50 * time.Millisecond) select { case <-doneCh: - t.Fatal("should not finish quickly") - case <-time.After(50 * time.Millisecond): + t.Fatalf("expected to finish sometime after %s finished in %s", mustExceed, time.Since(startTime)) + case <-time.After(mustExceed): + t.Logf("correctly took longer than %s", mustExceed) } // Stop it + stopTime := time.Now() p.Stop() + maxTempl := "expected to finish under %s, finished in %s" + finishWithin := (2 * time.Second) select { case <-doneCh: - case <-time.After(2 * time.Second): - t.Fatal("should finish") + t.Logf(maxTempl, finishWithin, time.Since(stopTime)) + case <-time.After(finishWithin): + t.Fatalf(maxTempl, finishWithin, time.Since(stopTime)) } }