Skip to content

Commit c3bfcc2

Browse files
committed
Kill a debuggee process fastly if a test fails
1 parent a9bec25 commit c3bfcc2

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

test/support/console_test_case.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,20 @@ 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_fail = true
200+
raise
198201
ensure
199-
kill_remote_debuggee test_info
202+
kill_remote_debuggee(test_info, failed: is_fail == true)
200203
# kill debug console process
201204
read.close
202205
write.close
203-
kill_safely pid, :debugger, test_info
206+
if is_fail == true
207+
kill_safely pid, :debugger, test_info, sec: 0
208+
end
209+
if name = test_info.failed_process && !is_fail
210+
flunk(create_message("Expected the #{name} program to finish", test_info))
211+
end
204212
end
205213
end
206214
end

test/support/test_case.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ def wait_pid pid, sec
122122
true
123123
end
124124

125-
def kill_safely pid, name, test_info
126-
return if wait_pid pid, TIMEOUT_SEC
125+
def kill_safely pid, name, test_info, sec: TIMEOUT_SEC
126+
return if wait_pid pid, sec
127127

128128
test_info.failed_process = name
129129

@@ -141,10 +141,14 @@ def check_error(error, test_info)
141141
end
142142
end
143143

144-
def kill_remote_debuggee test_info
144+
def kill_remote_debuggee test_info, failed: false
145145
return unless r = test_info.remote_info
146146

147-
kill_safely r.pid, :remote, test_info
147+
if failed
148+
kill_safely r.pid, :remote, test_info, sec: 2
149+
else
150+
kill_safely r.pid, :remote, test_info
151+
end
148152
r.reader_thread.kill
149153
# Because the debuggee may be terminated by executing the following operations, we need to run them after `kill_safely` method.
150154
r.r.close

0 commit comments

Comments
 (0)