Skip to content

Commit 3229bac

Browse files
committed
Make several protocol test helpers official
1 parent 05480ec commit 3229bac

File tree

4 files changed

+64
-60
lines changed

4 files changed

+64
-60
lines changed

CONTRIBUTING.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,22 @@ Execute debugging `program` with `&scenario`. If you want to test it only for DA
320320

321321
`run_protocol_scenario program, cdp: false ...`
322322

323+
- attach_to_dap_server(terminate_debuggee:)
324+
325+
Attach to the running DAP server through UNIX Domain Socket.
326+
327+
- attach_to_cdp_server
328+
329+
Attach to the running CDP server through TCP/IP.
330+
331+
- req_dap_disconnect
332+
333+
Disconnect from the currently connected DAP server.
334+
335+
- req_cdp_disconnect
336+
337+
Disconnect from the currently connected CDP server.
338+
323339
- req_add_breakpoint(lineno, path: temp_file_path, cond: nil)
324340

325341
Sends request to rdbg to add a breakpoint.

test/protocol/disconnect_cdp_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class DisconnectCDPTest < ProtocolTestCase
2121

2222
def test_closing_cdp_connection_doesnt_kill_the_debuggee
2323
run_protocol_scenario PROGRAM, dap: false do
24-
req_disconnect
24+
req_cdp_disconnect
2525
attach_to_cdp_server
2626
req_terminate_debuggee
2727
end

test/protocol/disconnect_dap_test.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ def test_disconnect_with_terminateDebuggee_kills_debuggee
3939

4040
private
4141

42-
def req_dap_disconnect(terminate_debuggee:)
43-
send_dap_request 'disconnect', terminateDebuggee: terminate_debuggee
44-
close_reader
45-
end
46-
4742
def suspend_debugee
4843
send_dap_request "pause", threadId: 1
4944
end

test/support/protocol_test_case.rb

Lines changed: 47 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,51 @@ def run_protocol_scenario program, dap: true, cdp: true, &scenario
5050
end
5151
end
5252

53+
def attach_to_dap_server
54+
@sock = Socket.unix @remote_info.sock_path
55+
@seq = 1
56+
@reader_thread = Thread.new do
57+
while res = recv_response
58+
@queue.push res
59+
end
60+
rescue Detach
61+
end
62+
sleep 0.001 while @reader_thread.status != 'sleep'
63+
@reader_thread.run
64+
INITIALIZE_DAP_MSGS.each{|msg| send(**msg)}
65+
end
66+
67+
def attach_to_cdp_server
68+
sock = Socket.tcp HOST, @remote_info.port
69+
70+
Timeout.timeout(TIMEOUT_SEC) do
71+
sleep 0.001 until @remote_info.debuggee_backlog.join.include? 'Connected'
72+
end
73+
74+
@web_sock = WebSocketClient.new sock
75+
@web_sock.handshake @remote_info.port, '/'
76+
@id = 1
77+
@reader_thread = Thread.new do
78+
while res = @web_sock.extract_data
79+
@queue.push res
80+
end
81+
rescue Detach
82+
end
83+
sleep 0.001 while @reader_thread.status != 'sleep'
84+
@reader_thread.run
85+
INITIALIZE_CDP_MSGS.each{|msg| send(**msg)}
86+
end
87+
88+
def req_dap_disconnect(terminate_debuggee:)
89+
send_dap_request 'disconnect', restart: false, terminateDebuggee: terminate_debuggee
90+
close_reader
91+
end
92+
93+
def req_cdp_disconnect
94+
@web_sock.send_close_connection
95+
close_reader
96+
end
97+
5398
def req_add_breakpoint lineno, path: temp_file_path, cond: nil
5499
case get_target_ui
55100
when 'vscode'
@@ -304,7 +349,8 @@ def execute_cdp_scenario scenario
304349
@backlog = []
305350

306351
attach_to_cdp_server
307-
assert_cdp_connected
352+
res = find_response :method, 'Debugger.paused', 'C<D'
353+
@crt_frames = res.dig(:params, :callFrames)
308354
scenario.call
309355

310356
flunk create_protocol_message "Expected the debuggee program to finish" unless wait_pid @remote_info.pid, TIMEOUT_SEC
@@ -316,19 +362,6 @@ def execute_cdp_scenario scenario
316362
@remote_info&.w&.close
317363
end
318364

319-
def req_disconnect
320-
case get_target_ui
321-
when 'vscode'
322-
send_dap_request 'disconnect',
323-
restart: false,
324-
terminateDebuggee: false
325-
when 'chrome'
326-
@web_sock.send_close_connection
327-
end
328-
329-
close_reader
330-
end
331-
332365
def req_set_breakpoints_on_dap
333366
bps_map = {temp_file_path => []}
334367
@bps.each{|tar_path, tar_lineno, condition|
@@ -364,48 +397,8 @@ def close_reader
364397
end
365398
end
366399

367-
def attach_to_dap_server
368-
@sock = Socket.unix @remote_info.sock_path
369-
@seq = 1
370-
@reader_thread = Thread.new do
371-
while res = recv_response
372-
@queue.push res
373-
end
374-
rescue Detach
375-
end
376-
sleep 0.001 while @reader_thread.status != 'sleep'
377-
@reader_thread.run
378-
INITIALIZE_DAP_MSGS.each{|msg| send(**msg)}
379-
end
380-
381400
HOST = '127.0.0.1'
382401

383-
def attach_to_cdp_server
384-
sock = Socket.tcp HOST, @remote_info.port
385-
386-
Timeout.timeout(TIMEOUT_SEC) do
387-
sleep 0.001 until @remote_info.debuggee_backlog.join.include? 'Connected'
388-
end
389-
390-
@web_sock = WebSocketClient.new sock
391-
@web_sock.handshake @remote_info.port, '/'
392-
@id = 1
393-
@reader_thread = Thread.new do
394-
while res = @web_sock.extract_data
395-
@queue.push res
396-
end
397-
rescue Detach
398-
end
399-
sleep 0.001 while @reader_thread.status != 'sleep'
400-
@reader_thread.run
401-
INITIALIZE_CDP_MSGS.each{|msg| send(**msg)}
402-
end
403-
404-
def assert_cdp_connected
405-
res = find_response :method, 'Debugger.paused', 'C<D'
406-
@crt_frames = res.dig(:params, :callFrames)
407-
end
408-
409402
JAVASCRIPT_TYPE_TO_CLASS_MAPS = {
410403
'string' => String,
411404
'number' => Integer,

0 commit comments

Comments
 (0)