mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
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)
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user