Skip to content

Commit

Permalink
Kill a debuggee process fastly if a test fails
Browse files Browse the repository at this point in the history
If AssertionFailedError occurs, we can send signals soon without waiting first.
  • Loading branch information
ono-max committed Apr 2, 2023
1 parent 61e378c commit f53295b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
4 changes: 0 additions & 4 deletions test/support/assertions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ def test_the_helper_raises_an_error_with_invalid_expectation
end

def test_the_test_fails_when_debuggee_on_unix_domain_socket_mode_doesnt_exist_after_scenarios
omit "too slow now"

assert_raise_message(/Expected to include `"foobar\\\\?/) do
prepare_test_environment(program, steps) do
debug_code_on_unix_domain_socket()
Expand All @@ -61,8 +59,6 @@ def test_the_test_fails_when_debuggee_on_unix_domain_socket_mode_doesnt_exist_af
end

def test_the_test_fails_when_debuggee_on_tcpip_mode_doesnt_exist_after_scenarios
omit "too slow now"

assert_raise_message(/Expected to include `"foobar\\\\?/) do
prepare_test_environment(program, steps) do
debug_code_on_tcpip()
Expand Down
7 changes: 5 additions & 2 deletions test/support/console_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,15 @@ def run_test_scenario cmd, test_info
# result of `gets` return this exception in some platform
rescue Timeout::Error
assert_block(create_message("TIMEOUT ERROR (#{TIMEOUT_SEC} sec)", test_info)) { false }
rescue Test::Unit::AssertionFailedError
is_assertion_failure = true
raise
ensure
kill_remote_debuggee test_info
kill_remote_debuggee test_info, force: is_assertion_failure
# kill debug console process
read.close
write.close
kill_safely pid
kill_safely pid, force: is_assertion_failure
end
end
end
Expand Down
16 changes: 12 additions & 4 deletions test/support/protocol_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,12 @@ def execute_dap_scenario scenario
is_assertion_failure = true
raise e
ensure
if kill_remote_debuggee(test_info) && !is_assertion_failure
flunk create_protocol_message "Expected the debuggee program to finish"
if is_assertion_failure
kill_remote_debuggee(test_info, force: true)
else
if kill_remote_debuggee(test_info)
flunk create_protocol_message "Expected the debuggee program to finish"
end
end
# Because the debuggee may be terminated by executing the following operations, we need to run them after `kill_remote_debuggee` method.
@reader_thread&.kill
Expand Down Expand Up @@ -379,8 +383,12 @@ def execute_cdp_scenario_ scenario
is_assertion_failure = true
raise e
ensure
if kill_remote_debuggee(test_info) && !is_assertion_failure
flunk create_protocol_message "Expected the debuggee program to finish"
if is_assertion_failure
kill_remote_debuggee(test_info, force: true)
else
if kill_remote_debuggee(test_info)
flunk create_protocol_message "Expected the debuggee program to finish"
end
end
# Because the debuggee may be terminated by executing the following operations, we need to run them after `kill_remote_debuggee` method.
@reader_thread&.kill
Expand Down
2 changes: 0 additions & 2 deletions test/support/protocol_test_case_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def test_the_test_fails_when_debuggee_doesnt_exit
end

def test_the_assertion_failure_takes_presedence_over_debuggee_not_exiting
omit "too slow now"

program = <<~RUBY
1| a = 2
2| b = 3
Expand Down
10 changes: 6 additions & 4 deletions test/support/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ def wait_pid pid, sec
true
end

def kill_safely pid
return false if wait_pid pid, TIMEOUT_SEC
def kill_safely pid, force: false
unless force
return false if wait_pid pid, TIMEOUT_SEC
end

Process.kill :TERM, pid
return true if wait_pid pid, 0.2
Expand All @@ -141,10 +143,10 @@ def check_error(error, test_info)
end
end

def kill_remote_debuggee test_info
def kill_remote_debuggee test_info, force: false
return false unless r = test_info.remote_info

force_killed = kill_safely r.pid
force_killed = kill_safely r.pid, force: force
r.reader_thread.kill
# Because the debuggee may be terminated by executing the following operations, we need to run them after `kill_safely` method.
r.r.close
Expand Down

0 comments on commit f53295b

Please sign in to comment.