Skip to content

Commit

Permalink
Read data from the I/O stream of the remote debuggee every commands a…
Browse files Browse the repository at this point in the history
…re typed

Fix #318
  • Loading branch information
ono-max committed Oct 9, 2021
1 parent 77840ed commit 7f8db43
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions test/support/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ def create_message fail_msg, test_info

debuggee_msg =
if test_info.mode != 'LOCAL'
debuggee_backlog = collect_debuggee_backlog(test_info)

<<~DEBUGGEE_MSG.chomp
--------------------
| Debuggee Session |
--------------------
> #{debuggee_backlog.join('> ')}
> #{test_info.debuggee_backlog.join('> ')}
DEBUGGEE_MSG
end

Expand All @@ -52,22 +51,15 @@ def create_message fail_msg, test_info
end

def collect_debuggee_backlog test_info
backlog = []

begin
Timeout.timeout(TIMEOUT_SEC) do
while (line = test_info.remote_debuggee_info[0].gets)
backlog << line
end
end
rescue Timeout::Error, Errno::EIO
# result of `gets` return Errno::EIO in some platform
# https://github.com/ruby/ruby/blob/master/ext/pty/pty.c#L729-L736
while line = test_info.remote_debuggee_info[0].read_nonblock(4096)
test_info.debuggee_backlog.push(line)
sleep(0.1)
end
backlog
rescue IO::WaitReadable, EOFError
# The `read_nonblock` method occurs IO::WaitReadable if I/O stream has no data.
end

TestInfo = Struct.new(:queue, :remote_debuggee_info, :mode, :debugger_backlog, :debugger_last_backlog, :internal_info)
TestInfo = Struct.new(:queue, :remote_debuggee_info, :mode, :debugger_backlog, :debugger_last_backlog, :debuggee_backlog, :internal_info)

MULTITHREADED_TEST = !(%w[1 true].include? ENV['RUBY_DEBUG_TEST_DISABLE_THREADS'])

Expand Down Expand Up @@ -172,6 +164,7 @@ def debug_on_tcpip repl_prompt = /\(rdbg:remote\)/, test_info

def run_test_scenario cmd, repl_prompt, test_info
PTY.spawn(cmd) do |read, write, pid|
test_info.debuggee_backlog = []
test_info.debugger_backlog = []
test_info.debugger_last_backlog = []
begin
Expand Down Expand Up @@ -218,6 +211,7 @@ def run_test_scenario cmd, repl_prompt, test_info
a.call test_info
end
when repl_prompt
collect_debuggee_backlog(test_info) if test_info.remote_debuggee_info
# check if the previous command breaks the debugger before continuing
check_error(/REPL ERROR/, test_info)
end
Expand Down

0 comments on commit 7f8db43

Please sign in to comment.