@ -824,14 +824,20 @@ func TestApply_refresh(t *testing.T) {
}
func TestApply_shutdown ( t * testing . T ) {
stopped := false
stopCh := make ( chan struct { } )
stopReplyCh := make ( chan struct { } )
cancelled := false
cancelDone := make ( chan struct { } )
testShutdownHook = func ( ) {
cancelled = true
close ( cancelDone )
}
defer func ( ) {
testShutdownHook = nil
} ( )
statePath := testTempFile ( t )
p := testProvider ( )
shutdownCh := make ( chan struct { } )
ui := new ( cli . MockUi )
c := & ApplyCommand {
Meta : Meta {
@ -857,10 +863,10 @@ func TestApply_shutdown(t *testing.T) {
* terraform . InstanceInfo ,
* terraform . InstanceState ,
* terraform . InstanceDiff ) ( * terraform . InstanceState , error ) {
if ! stopped {
stopped = true
close ( stopCh )
<- stopReplyCh
if ! cancelled {
shutdownCh <- struct { } { }
<- cancelDone
}
return & terraform . InstanceState {
@ -871,18 +877,6 @@ func TestApply_shutdown(t *testing.T) {
} , nil
}
go func ( ) {
<- stopCh
shutdownCh <- struct { } { }
// This is really dirty, but we have no other way to assure that
// tf.Stop() has been called. This doesn't assure it either, but
// it makes it much more certain.
time . Sleep ( 50 * time . Millisecond )
close ( stopReplyCh )
} ( )
args := [ ] string {
"-state" , statePath ,
"-auto-approve" ,
@ -896,6 +890,10 @@ func TestApply_shutdown(t *testing.T) {
t . Fatalf ( "err: %s" , err )
}
if ! cancelled {
t . Fatal ( "command not cancelled" )
}
state := testStateRead ( t , statePath )
if state == nil {
t . Fatal ( "state should not be nil" )