Skip to content

Commit 5039226

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

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

test/support/test_case.rb

+17-10
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,19 @@ 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
169174
end
170175

171176
remote_info.reader_thread = Thread.new(remote_info) do |info|
@@ -191,14 +196,16 @@ def setup_unix_domain_socket_remote_debuggee
191196
remote_info
192197
end
193198

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-
199199
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
200+
remote_info = setup_remote_debuggee("#{RDBG_EXECUTABLE} -O --port=0 -- #{temp_file_path}")
201+
port = nil
202+
remote_info.debuggee_backlog.each{|line|
203+
if /Debugger can attach via TCP\/IP \(.+:(\d+)\)/ =~ line
204+
port = $1.to_i
205+
end
206+
}
207+
raise "can not find TCP/IP port with backlog: #{remote_info.debuggee_backlog.inspect}" unless port
208+
remote_info.port = port
202209
Timeout.timeout(TIMEOUT_SEC) do
203210
sleep 0.001 until remote_info.debuggee_backlog.join.include? remote_info.port.to_s
204211
end

0 commit comments

Comments
 (0)