Skip to content

Commit 80644fc

Browse files
ono-maxko1
authored andcommitted
Kill a debuggee process fastly if a test fails
If AssertionFailedError occurs, we can send signals soon without waiting first.
1 parent d88994f commit 80644fc

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

test/support/assertions_test.rb

-4
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ def test_the_helper_raises_an_error_with_invalid_expectation
5151
end
5252

5353
def test_the_test_fails_when_debuggee_on_unix_domain_socket_mode_doesnt_exist_after_scenarios
54-
omit "too slow now"
55-
5654
assert_raise_message(/Expected to include `"foobar\\\\?/) do
5755
prepare_test_environment(program, steps) do
5856
debug_code_on_unix_domain_socket()
@@ -61,8 +59,6 @@ def test_the_test_fails_when_debuggee_on_unix_domain_socket_mode_doesnt_exist_af
6159
end
6260

6361
def test_the_test_fails_when_debuggee_on_tcpip_mode_doesnt_exist_after_scenarios
64-
omit "too slow now"
65-
6662
assert_raise_message(/Expected to include `"foobar\\\\?/) do
6763
prepare_test_environment(program, steps) do
6864
debug_code_on_tcpip()

test/support/console_test_case.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,15 @@ def run_test_scenario cmd, test_info
195195
# result of `gets` return this exception in some platform
196196
rescue Timeout::Error
197197
assert_block(create_message("TIMEOUT ERROR (#{TIMEOUT_SEC} sec)", test_info)) { false }
198+
rescue Test::Unit::AssertionFailedError
199+
is_assertion_failure = true
200+
raise
198201
ensure
199-
kill_remote_debuggee test_info
202+
kill_remote_debuggee test_info, force: is_assertion_failure
200203
# kill debug console process
201204
read.close
202205
write.close
203-
kill_safely pid
206+
kill_safely pid, force: is_assertion_failure
204207
end
205208
end
206209
end

test/support/protocol_test_case.rb

+12-4
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,12 @@ def execute_dap_scenario scenario
346346
is_assertion_failure = true
347347
raise e
348348
ensure
349-
if kill_remote_debuggee(test_info) && !is_assertion_failure
350-
flunk create_protocol_message "Expected the debuggee program to finish"
349+
if is_assertion_failure
350+
kill_remote_debuggee(test_info, force: true)
351+
else
352+
if kill_remote_debuggee(test_info)
353+
flunk create_protocol_message "Expected the debuggee program to finish"
354+
end
351355
end
352356
# Because the debuggee may be terminated by executing the following operations, we need to run them after `kill_remote_debuggee` method.
353357
@reader_thread&.kill
@@ -379,8 +383,12 @@ def execute_cdp_scenario_ scenario
379383
is_assertion_failure = true
380384
raise e
381385
ensure
382-
if kill_remote_debuggee(test_info) && !is_assertion_failure
383-
flunk create_protocol_message "Expected the debuggee program to finish"
386+
if is_assertion_failure
387+
kill_remote_debuggee(test_info, force: true)
388+
else
389+
if kill_remote_debuggee(test_info)
390+
flunk create_protocol_message "Expected the debuggee program to finish"
391+
end
384392
end
385393
# Because the debuggee may be terminated by executing the following operations, we need to run them after `kill_remote_debuggee` method.
386394
@reader_thread&.kill

test/support/protocol_test_case_test.rb

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ def test_the_test_fails_when_debuggee_doesnt_exit
1818
end
1919

2020
def test_the_assertion_failure_takes_presedence_over_debuggee_not_exiting
21-
omit "too slow now"
22-
2321
program = <<~RUBY
2422
1| a = 2
2523
2| b = 3

test/support/test_case.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ def wait_pid pid, sec
122122
true
123123
end
124124

125-
def kill_safely pid
126-
return false if wait_pid pid, TIMEOUT_SEC
125+
def kill_safely pid, force: false
126+
unless force
127+
return false if wait_pid pid, TIMEOUT_SEC
128+
end
127129

128130
Process.kill :TERM, pid
129131
return true if wait_pid pid, 0.2
@@ -141,10 +143,10 @@ def check_error(error, test_info)
141143
end
142144
end
143145

144-
def kill_remote_debuggee test_info
146+
def kill_remote_debuggee test_info, force: false
145147
return false unless r = test_info.remote_info
146148

147-
force_killed = kill_safely r.pid
149+
force_killed = kill_safely r.pid, force: force
148150
r.reader_thread.kill
149151
# Because the debuggee may be terminated by executing the following operations, we need to run them after `kill_safely` method.
150152
r.r.close

0 commit comments

Comments
 (0)