@@ -65,30 +65,9 @@ def attach_to_dap_server
6565 end
6666
6767 def attach_to_cdp_server
68- body = get_request HOST , @remote_info . port , '/json'
69- Timeout . timeout ( TIMEOUT_SEC ) do
70- sleep 0.001 until @remote_info . debuggee_backlog . join . include? 'Disconnected.'
71- end
72-
73- sock = Socket . tcp HOST , @remote_info . port
74- uuid = body [ 0 ] [ :id ]
75-
76- Timeout . timeout ( TIMEOUT_SEC ) do
77- sleep 0.001 until @remote_info . debuggee_backlog . join . match? ( /Disconnected\. \R .*Connected/ )
68+ retry_connect do
69+ attach_to_cdp_server_
7870 end
79-
80- @web_sock = WebSocketClient . new sock
81- @web_sock . handshake @remote_info . port , uuid
82- @id = 1
83- @reader_thread = Thread . new do
84- while res = @web_sock . extract_data
85- @queue . push res
86- end
87- rescue Detach
88- end
89- sleep 0.001 while @reader_thread . status != 'sleep'
90- @reader_thread . run
91- INITIALIZE_CDP_MSGS . each { |msg | send ( **msg ) }
9271 end
9372
9473 def req_dap_disconnect ( terminate_debuggee :)
@@ -324,6 +303,33 @@ def assert_watch_result expected, expression, frame_idx: 0
324303
325304 # Not API
326305
306+ def attach_to_cdp_server_
307+ body = get_request HOST , @remote_info . port , '/json'
308+ Timeout . timeout ( TIMEOUT_SEC ) do
309+ sleep 0.001 until @remote_info . debuggee_backlog . join . include? 'Disconnected.'
310+ end
311+
312+ sock = Socket . tcp HOST , @remote_info . port
313+ uuid = body [ 0 ] [ :id ]
314+
315+ Timeout . timeout ( TIMEOUT_SEC ) do
316+ sleep 0.001 until @remote_info . debuggee_backlog . join . match? ( /Disconnected\. \R .*Connected/ )
317+ end
318+
319+ @web_sock = WebSocketClient . new sock
320+ @web_sock . handshake @remote_info . port , uuid
321+ @id = 1
322+ @reader_thread = Thread . new do
323+ while res = @web_sock . extract_data
324+ @queue . push res
325+ end
326+ rescue Detach
327+ end
328+ sleep 0.001 while @reader_thread . status != 'sleep'
329+ @reader_thread . run
330+ INITIALIZE_CDP_MSGS . each { |msg | send ( **msg ) }
331+ end
332+
327333 def execute_dap_scenario scenario
328334 ENV [ 'RUBY_DEBUG_TEST_UI' ] = 'vscode'
329335
@@ -396,9 +402,15 @@ def execute_cdp_scenario_ scenario
396402 end
397403
398404 def execute_cdp_scenario scenario
405+ retry_connect do
406+ execute_cdp_scenario_ scenario
407+ end
408+ end
409+
410+ def retry_connect
399411 retry_cnt = 0
400412 begin
401- execute_cdp_scenario_ scenario
413+ yield
402414 rescue Errno ::ECONNREFUSED
403415 if ( retry_cnt += 1 ) > 10
404416 STDERR . puts "retry #{ retry_cnt } but can not connect!"
0 commit comments