Skip to content

Commit

Permalink
Make sure to kill remote debuggee in the protocol test
Browse files Browse the repository at this point in the history
  • Loading branch information
ono-max committed Nov 20, 2022
1 parent d7f181c commit 90d6041
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
28 changes: 16 additions & 12 deletions test/support/protocol_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,10 @@ def assert_watch_result expected, expression, frame_idx: 0
def execute_dap_scenario scenario
ENV['RUBY_DEBUG_TEST_UI'] = 'vscode'

@remote_info = setup_unix_domain_socket_remote_debuggee
# TestInfo is defined to use kill_remote_debuggee method.
test_info = TestInfo.new

@remote_info = test_info.remote_info = setup_unix_domain_socket_remote_debuggee
Timeout.timeout(TIMEOUT_SEC) do
sleep 0.001 until @remote_info.debuggee_backlog.join.include? 'connection...'
end
Expand All @@ -294,21 +297,23 @@ def execute_dap_scenario scenario

attach_to_dap_server
scenario.call

flunk create_protocol_message "Expected the debuggee program to finish" unless wait_pid @remote_info.pid, TIMEOUT_SEC
ensure
@reader_thread&.kill
@sock&.close
@remote_info&.reader_thread&.kill
@remote_info&.r&.close
@remote_info&.w&.close
kill_remote_debuggee test_info
if name = test_info.failed_process
flunk create_protocol_message "Expected the debuggee program to finish"
end
end

def execute_cdp_scenario_ scenario
ENV['RUBY_DEBUG_TEST_UI'] = 'chrome'

# TestInfo is defined to use kill_remote_debuggee method.
test_info = TestInfo.new

@web_sock = nil
@remote_info = setup_tcpip_remote_debuggee
@remote_info = test_info.remote_info = setup_tcpip_remote_debuggee
Timeout.timeout(TIMEOUT_SEC) do
sleep 0.001 until @remote_info.debuggee_backlog.join.include? @remote_info.port.to_s
end
Expand All @@ -320,14 +325,13 @@ def execute_cdp_scenario_ scenario

attach_to_cdp_server
scenario.call

flunk create_protocol_message "Expected the debuggee program to finish" unless wait_pid @remote_info.pid, TIMEOUT_SEC
ensure
@reader_thread&.kill
@web_sock&.close
@remote_info&.reader_thread&.kill
@remote_info&.r&.close
@remote_info&.w&.close
kill_remote_debuggee test_info
if name = test_info.failed_process
flunk create_protocol_message "Expected the debuggee program to finish"
end
end

def execute_cdp_scenario scenario
Expand Down
18 changes: 18 additions & 0 deletions test/support/protocol_test_case_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require_relative 'protocol_test_case'

module DEBUGGER__
class TestFrameworkTestHOge < ProtocolTestCase
PROGRAM = <<~RUBY
1| a=1
RUBY

def test_the_test_fails_when_debuggee_doesnt_exit
assert_fail_assertion do
run_protocol_scenario PROGRAM do
end
end
end
end
end
5 changes: 4 additions & 1 deletion test/support/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def wait_pid pid, sec
end

false
rescue Errno::ECHILD
true
end

def kill_safely pid, name, test_info
Expand All @@ -142,10 +144,11 @@ def check_error(error, test_info)
def kill_remote_debuggee test_info
return unless r = test_info.remote_info

kill_safely r.pid, :remote, test_info
# Because the debuggee may be terminated by executing the following operations, we need to run them after `kill_safely` method.
r.reader_thread.kill
r.r.close
r.w.close
kill_safely r.pid, :remote, test_info
end

def setup_remote_debuggee(cmd)
Expand Down

0 comments on commit 90d6041

Please sign in to comment.