ignore error in plan shutdown test
The error was being silently dropped before. There is an interpolation error, because the plan is canceled before some of the resources can be evaluated. There might be a better way to handle this in the walk cancellation, but the behavior has not changed. Make the plan and apply shutdown match implementation-wise
This commit is contained in:
parent
67a6152091
commit
ecd9ef0f77
|
@ -824,12 +824,11 @@ func TestApply_refresh(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestApply_shutdown(t *testing.T) {
|
||||
cancelled := false
|
||||
stopped := make(chan struct{})
|
||||
cancelled := make(chan struct{})
|
||||
shutdownCh := make(chan struct{})
|
||||
|
||||
statePath := testTempFile(t)
|
||||
p := testProvider()
|
||||
shutdownCh := make(chan struct{})
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
c := &ApplyCommand{
|
||||
|
@ -841,8 +840,7 @@ func TestApply_shutdown(t *testing.T) {
|
|||
}
|
||||
|
||||
p.StopFn = func() error {
|
||||
close(stopped)
|
||||
cancelled = true
|
||||
close(cancelled)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -858,15 +856,26 @@ func TestApply_shutdown(t *testing.T) {
|
|||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
var once sync.Once
|
||||
p.ApplyFn = func(
|
||||
*terraform.InstanceInfo,
|
||||
*terraform.InstanceState,
|
||||
*terraform.InstanceDiff) (*terraform.InstanceState, error) {
|
||||
|
||||
// only cancel once
|
||||
if !cancelled {
|
||||
once.Do(func() {
|
||||
shutdownCh <- struct{}{}
|
||||
<-stopped
|
||||
}
|
||||
})
|
||||
|
||||
// Because of the internal lock in the MockProvider, we can't
|
||||
// coordiante directly with the calling of Stop, and making the
|
||||
// MockProvider concurrent is disruptive to a lot of existing tests.
|
||||
// Wait here a moment to help make sure the main goroutine gets to the
|
||||
// Stop call before we exit, or the plan may finish before it can be
|
||||
// canceled.
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
return &terraform.InstanceState{
|
||||
ID: "foo",
|
||||
Attributes: map[string]string{
|
||||
|
@ -888,7 +897,9 @@ func TestApply_shutdown(t *testing.T) {
|
|||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if !cancelled {
|
||||
select {
|
||||
case <-cancelled:
|
||||
default:
|
||||
t.Fatal("command not cancelled")
|
||||
}
|
||||
|
||||
|
|
|
@ -835,8 +835,8 @@ func TestPlan_detailedExitcode_emptyDiff(t *testing.T) {
|
|||
|
||||
func TestPlan_shutdown(t *testing.T) {
|
||||
cancelled := make(chan struct{})
|
||||
|
||||
shutdownCh := make(chan struct{})
|
||||
|
||||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &PlanCommand{
|
||||
|
@ -880,8 +880,10 @@ func TestPlan_shutdown(t *testing.T) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
if code := c.Run([]string{testFixturePath("apply-shutdown")}); code != 0 {
|
||||
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
||||
if code := c.Run([]string{testFixturePath("apply-shutdown")}); code != 1 {
|
||||
// FIXME: we should be able to avoid the error during evaluation
|
||||
// the early exit isn't caught before the interpolation is evaluated
|
||||
t.Fatal(ui.OutputWriter.String())
|
||||
}
|
||||
|
||||
select {
|
||||
|
|
Loading…
Reference in New Issue