Skip to content

Commit 4ad3c3c

Browse files
committed
use freeport with --port=0
`setup_remote_debuggee` wait for "waiting" message and "port informatioin" message, too.
1 parent ba72e84 commit 4ad3c3c

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

test/support/test_case.rb

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,22 @@ def setup_remote_debuggee(cmd)
158158
remote_info.debuggee_backlog = []
159159

160160
line = nil
161+
msg1 = msg2 = nil
161162

162163
Timeout.timeout(TIMEOUT_SEC) do
163164
line = remote_info.r.gets
164165
remote_info.debuggee_backlog << line
165166

166-
# wait for first "wait for debugger connection" output
167-
break if /wait for debugger connection/ =~ line
168-
redo
167+
# wait for two lines (order is unstable)
168+
case line
169+
when /\ADEBUGGER: Debugger can attach via/
170+
msg1 = true
171+
when /\ADEBUGGER: wait for debugger connection/
172+
msg2 = true
173+
end
174+
175+
break if msg1 && msg2
176+
redo # loop
169177
end
170178

171179
remote_info.reader_thread = Thread.new(remote_info) do |info|
@@ -191,14 +199,16 @@ def setup_unix_domain_socket_remote_debuggee
191199
remote_info
192200
end
193201

194-
# search free port by opening server socket with port 0
195-
Socket.tcp_server_sockets(0).tap do |ss|
196-
TCPIP_PORT = ss.first.local_address.ip_port
197-
end.each{|s| s.close}
198-
199202
def setup_tcpip_remote_debuggee
200-
remote_info = setup_remote_debuggee("#{RDBG_EXECUTABLE} -O --port=#{TCPIP_PORT} -- #{temp_file_path}")
201-
remote_info.port = TCPIP_PORT
203+
remote_info = setup_remote_debuggee("#{RDBG_EXECUTABLE} -O --port=0 -- #{temp_file_path}")
204+
port = nil
205+
remote_info.debuggee_backlog.each{|line|
206+
if /Debugger can attach via TCP\/IP \(.+:(\d+)\)/ =~ line
207+
port = $1.to_i
208+
end
209+
}
210+
raise "can not find TCP/IP port with backlog: #{remote_info.debuggee_backlog.inspect}" unless port
211+
remote_info.port = port
202212
Timeout.timeout(TIMEOUT_SEC) do
203213
sleep 0.001 until remote_info.debuggee_backlog.join.include? remote_info.port.to_s
204214
end

0 commit comments

Comments
 (0)