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.
This commit is contained in:
parent
6562e97799
commit
47484e23fe
|
@ -58,26 +58,36 @@ func TestResourceProvider_stop(t *testing.T) {
|
||||||
output := new(terraform.MockUIOutput)
|
output := new(terraform.MockUIOutput)
|
||||||
p := Provisioner()
|
p := Provisioner()
|
||||||
|
|
||||||
var err error
|
|
||||||
doneCh := make(chan struct{})
|
doneCh := make(chan struct{})
|
||||||
|
startTime := time.Now()
|
||||||
go func() {
|
go func() {
|
||||||
defer close(doneCh)
|
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 {
|
select {
|
||||||
case <-doneCh:
|
case <-doneCh:
|
||||||
t.Fatal("should not finish quickly")
|
t.Fatalf("expected to finish sometime after %s finished in %s", mustExceed, time.Since(startTime))
|
||||||
case <-time.After(50 * time.Millisecond):
|
case <-time.After(mustExceed):
|
||||||
|
t.Logf("correctly took longer than %s", mustExceed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop it
|
// Stop it
|
||||||
|
stopTime := time.Now()
|
||||||
p.Stop()
|
p.Stop()
|
||||||
|
|
||||||
|
maxTempl := "expected to finish under %s, finished in %s"
|
||||||
|
finishWithin := (2 * time.Second)
|
||||||
select {
|
select {
|
||||||
case <-doneCh:
|
case <-doneCh:
|
||||||
case <-time.After(2 * time.Second):
|
t.Logf(maxTempl, finishWithin, time.Since(stopTime))
|
||||||
t.Fatal("should finish")
|
case <-time.After(finishWithin):
|
||||||
|
t.Fatalf(maxTempl, finishWithin, time.Since(stopTime))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue