Skip to content

Commit c9fbb7d

Browse files
committed
Fix test framework for 4e7c600
1 parent 8f9febd commit c9fbb7d

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

test/support/cdp_utils.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ def setup_chrome_debuggee
3434
def connect_to_cdp_server
3535
ENV['RUBY_DEBUG_TEST_MODE'] = 'true'
3636

37+
body = get_request HOST, @remote_info.port, '/json'
3738
sock = Socket.tcp HOST, @remote_info.port
39+
uuid = body[0][:id]
40+
3841
Timeout.timeout(TIMEOUT_SEC) do
39-
sleep 0.001 until @remote_info.debuggee_backlog.join.include? 'Connected'
42+
sleep 0.001 until @remote_info.debuggee_backlog.join.match? /Disconnected\.\R.*Connected/
4043
end
4144
@web_sock = WebSocketClient.new sock
42-
@web_sock.handshake @remote_info.port, '/'
45+
@web_sock.handshake @remote_info.port, uuid
4346
@reader_thread = Thread.new do
4447
Thread.current.abort_on_exception = true
4548
while res = @web_sock.extract_data

test/support/protocol_test_case.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,14 +394,16 @@ def attach_to_dap_server
394394
HOST = '127.0.0.1'
395395

396396
def attach_to_cdp_server
397+
body = get_request HOST, @remote_info.port, '/json'
397398
sock = Socket.tcp HOST, @remote_info.port
399+
uuid = body[0][:id]
398400

399401
Timeout.timeout(TIMEOUT_SEC) do
400-
sleep 0.001 until @remote_info.debuggee_backlog.join.include? 'Connected'
402+
sleep 0.001 until @remote_info.debuggee_backlog.join.match? /Disconnected\.\R.*Connected/
401403
end
402404

403405
@web_sock = WebSocketClient.new sock
404-
@web_sock.handshake @remote_info.port, '/'
406+
@web_sock.handshake @remote_info.port, uuid
405407
@id = 1
406408
@reader_thread = Thread.new do
407409
while res = @web_sock.extract_data
@@ -797,9 +799,9 @@ def initialize s
797799
@sock = s
798800
end
799801

800-
def handshake port, path
802+
def handshake port, uuid
801803
key = SecureRandom.hex(11)
802-
@sock.print "GET #{path} HTTP/1.1\r\nHost: 127.0.0.1:#{port}\r\nConnection: Upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: #{key}==\r\n\r\n"
804+
@sock.print "GET /#{uuid} HTTP/1.1\r\nHost: 127.0.0.1:#{port}\r\nConnection: Upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: #{key}==\r\n\r\n"
803805
res = nil
804806
loop do
805807
res = @sock.readpartial 4092

test/support/test_case.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,5 +184,26 @@ def setup_tcpip_remote_debuggee
184184
remote_info.port = TCPIP_PORT
185185
remote_info
186186
end
187+
188+
# Debuggee sometimes sends msgs such as "out [1, 5] in ...".
189+
# This http request method is for ignoring them.
190+
def get_request host, port, path
191+
Timeout.timeout(TIMEOUT_SEC) do
192+
Socket.tcp(host, port){|sock|
193+
sock.print "GET #{path} HTTP/1.1\r\n"
194+
sock.close_write
195+
loop do
196+
case header = sock.gets
197+
when /Content-Length: (\d+)/
198+
b = sock.read(2)
199+
raise b.inspect unless b == "\r\n"
200+
201+
l = sock.read $1.to_i
202+
return JSON.parse l, symbolize_names: true
203+
end
204+
end
205+
}
206+
end
207+
end
187208
end
188209
end

0 commit comments

Comments
 (0)