@@ -410,6 +410,43 @@ def get_ack_diagnostics(is_command_noop)
410410
411411 end
412412
413+ context 'calling recover_from_crash when a lifecycle event is in-progress' do
414+
415+ setup do
416+ InstanceAgent ::Plugins ::CodeDeployPlugin ::DeploymentCommandTracker . stubs ( :check_deployment_event_inprogress? ) . returns ( true )
417+ InstanceAgent ::Plugins ::CodeDeployPlugin ::DeploymentCommandTracker . stubs ( :deployment_dir_path ) . returns ( "deployment-path" )
418+ InstanceAgent ::Plugins ::CodeDeployPlugin ::DeploymentCommandTracker . stubs ( :most_recent_host_command_identifier ) . returns ( "i-123" )
419+ InstanceAgent ::Plugins ::CodeDeployPlugin ::DeploymentCommandTracker . stubs ( :clean_ongoing_deployment_dir )
420+ end
421+
422+ should 'call PutHostCommandComplete' do
423+ @deploy_control_client . expects ( :put_host_command_complete ) .
424+ with ( :command_status => "Failed" ,
425+ :diagnostics => { :format => "JSON" , :payload => gather_diagnostics_from_failure_after_restart ( "" , "Failing in-progress lifecycle event after an agent restart." ) } ,
426+ :host_command_identifier => "i-123" )
427+
428+ @poller . recover_from_crash?
429+ end
430+ end
431+
432+ context 'calling recover_from_crash when a lifecycle event is not in-progress' do
433+
434+ setup do
435+ InstanceAgent ::Plugins ::CodeDeployPlugin ::DeploymentCommandTracker . stubs ( :check_deployment_event_inprogress? ) . returns ( false )
436+ InstanceAgent ::Plugins ::CodeDeployPlugin ::DeploymentCommandTracker . stubs ( :deployment_dir_path ) . returns ( "deployment-path" )
437+ InstanceAgent ::Plugins ::CodeDeployPlugin ::DeploymentCommandTracker . stubs ( :most_recent_host_command_identifier ) . returns ( "i-123" )
438+ InstanceAgent ::Plugins ::CodeDeployPlugin ::DeploymentCommandTracker . stubs ( :clean_ongoing_deployment_dir )
439+ end
440+
441+ should 'not call PutHostCommandComplete' do
442+ @put_host_command_complete_state . become ( 'never' )
443+ @deploy_control_client . expects ( :put_host_command_complete ) . never .
444+ when ( @put_host_command_complete_state . is ( 'never' ) )
445+
446+ @poller . recover_from_crash?
447+ end
448+ end
449+
413450 context 'when no deployment specification is given by GetDeploymentSpecification' do
414451
415452 setup do
@@ -447,7 +484,7 @@ def get_ack_diagnostics(is_command_noop)
447484
448485 should 'allow exceptions from execute_command to propagate to caller' do
449486 @executor . expects ( :execute_command ) .
450- raises ( "some error" )
487+ raises ( "some error" )
451488 @deploy_control_client . expects ( :put_host_command_complete ) .
452489 with ( :command_status => "Failed" ,
453490 :diagnostics => { :format => "JSON" , :payload => gather_diagnostics_from_error ( RuntimeError . new ( "some error" ) ) } ,
0 commit comments