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 01859a7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 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
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 01859a7

Please sign in to comment.