Skip to content

Commit

Permalink
Fix test framework for 4e7c600
Browse files Browse the repository at this point in the history
  • Loading branch information
ono-max committed Oct 24, 2022
1 parent 8f9febd commit c9fbb7d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
7 changes: 5 additions & 2 deletions test/support/cdp_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ def setup_chrome_debuggee
def connect_to_cdp_server
ENV['RUBY_DEBUG_TEST_MODE'] = 'true'

body = get_request HOST, @remote_info.port, '/json'
sock = Socket.tcp HOST, @remote_info.port
uuid = body[0][:id]

Timeout.timeout(TIMEOUT_SEC) do
sleep 0.001 until @remote_info.debuggee_backlog.join.include? 'Connected'
sleep 0.001 until @remote_info.debuggee_backlog.join.match? /Disconnected\.\R.*Connected/
end
@web_sock = WebSocketClient.new sock
@web_sock.handshake @remote_info.port, '/'
@web_sock.handshake @remote_info.port, uuid
@reader_thread = Thread.new do
Thread.current.abort_on_exception = true
while res = @web_sock.extract_data
Expand Down
10 changes: 6 additions & 4 deletions test/support/protocol_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,16 @@ def attach_to_dap_server
HOST = '127.0.0.1'

def attach_to_cdp_server
body = get_request HOST, @remote_info.port, '/json'
sock = Socket.tcp HOST, @remote_info.port
uuid = body[0][:id]

Timeout.timeout(TIMEOUT_SEC) do
sleep 0.001 until @remote_info.debuggee_backlog.join.include? 'Connected'
sleep 0.001 until @remote_info.debuggee_backlog.join.match? /Disconnected\.\R.*Connected/
end

@web_sock = WebSocketClient.new sock
@web_sock.handshake @remote_info.port, '/'
@web_sock.handshake @remote_info.port, uuid
@id = 1
@reader_thread = Thread.new do
while res = @web_sock.extract_data
Expand Down Expand Up @@ -797,9 +799,9 @@ def initialize s
@sock = s
end

def handshake port, path
def handshake port, uuid
key = SecureRandom.hex(11)
@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"
@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"
res = nil
loop do
res = @sock.readpartial 4092
Expand Down
21 changes: 21 additions & 0 deletions test/support/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,26 @@ def setup_tcpip_remote_debuggee
remote_info.port = TCPIP_PORT
remote_info
end

# Debuggee sometimes sends msgs such as "out [1, 5] in ...".
# This http request method is for ignoring them.
def get_request host, port, path
Timeout.timeout(TIMEOUT_SEC) do
Socket.tcp(host, port){|sock|
sock.print "GET #{path} HTTP/1.1\r\n"
sock.close_write
loop do
case header = sock.gets
when /Content-Length: (\d+)/
b = sock.read(2)
raise b.inspect unless b == "\r\n"

l = sock.read $1.to_i
return JSON.parse l, symbolize_names: true
end
end
}
end
end
end
end

0 comments on commit c9fbb7d

Please sign in to comment.