@@ -28,6 +28,39 @@ def setup
2828 end
2929 end
3030
31+ describe '#kill' do
32+ let ( :runner ) { ::Proxy ::Ansible ::Runner ::AnsibleRunner . allocate }
33+ let ( :hosts ) { [ 'host1.example.com' , 'host2.example.com' ] }
34+
35+ test 'marks every host failed before publishing exit statuses' do
36+ expected_exit_statuses = hosts . to_h { |host | [ host , 2 ] }
37+ runner . instance_variable_set ( :@process_manager , stub ( :pid => 1234 ) )
38+ runner . instance_variable_set ( :@inventory , { 'all' => { 'hosts' => hosts . to_h { |host | [ host , { } ] } } } )
39+ runner . instance_variable_set ( :@exit_statuses , hosts . to_h { |host | [ host , 0 ] } )
40+
41+ ::Process . expects ( :kill ) . with ( 'SIGTERM' , 1234 )
42+ runner . expects ( :publish_exit_status ) . with do |status |
43+ status == 2 && runner . instance_variable_get ( :@exit_statuses ) == expected_exit_statuses
44+ end
45+ runner . expects ( :broadcast_data ) . never
46+ runner . expects ( :close )
47+
48+ runner . kill
49+ end
50+ end
51+
52+ describe '#timeout' do
53+ let ( :runner ) { ::Proxy ::Ansible ::Runner ::AnsibleRunner . allocate }
54+
55+ test 'broadcasts the timeout message before killing the job' do
56+ runner . stubs ( :logger ) . returns ( stub ( :debug => nil ) )
57+ runner . expects ( :broadcast_data ) . with ( 'Timeout for execution passed, stopping the job' , 'stderr' )
58+ runner . expects ( :kill )
59+
60+ runner . timeout
61+ end
62+ end
63+
3164 describe '#rebuild_secrets' do
3265 let ( :inventory ) { { 'all' => { 'hosts' => { 'foreman.example.com' => { } } } } }
3366 let ( :host_secrets ) { { 'ansible_password' => 'letmein' , 'ansible_become_password' => 'iamroot' } }
0 commit comments