55import os
66import signal
77import tempfile
8+ import time
89
910import dap_server
1011from lldbsuite .test .decorators import *
1314
1415
1516class TestDAP_server (lldbdap_testcase .DAPTestCaseBase ):
16- def start_server (self , connection ):
17+ def start_server (
18+ self , connection , connection_timeout = None , wait_seconds_for_termination = None
19+ ):
1720 log_file_path = self .getBuildArtifact ("dap.txt" )
1821 (process , connection ) = dap_server .DebugAdapterServer .launch (
1922 executable = self .lldbDAPExec ,
2023 connection = connection ,
24+ connection_timeout = connection_timeout ,
2125 log_file = log_file_path ,
2226 )
2327
2428 def cleanup ():
25- process .terminate ()
29+ if wait_seconds_for_termination is not None :
30+ process .wait (wait_seconds_for_termination )
31+ else :
32+ process .terminate ()
2633
2734 self .addTearDownHook (cleanup )
2835
2936 return (process , connection )
3037
31- def run_debug_session (self , connection , name ):
38+ def run_debug_session (self , connection , name , sleep_seconds_in_middle = None ):
3239 self .dap_server = dap_server .DebugAdapterServer (
3340 connection = connection ,
3441 )
@@ -41,6 +48,8 @@ def run_debug_session(self, connection, name):
4148 args = [name ],
4249 disconnectAutomatically = False ,
4350 )
51+ if sleep_seconds_in_middle is not None :
52+ time .sleep (sleep_seconds_in_middle )
4453 self .set_source_breakpoints (source , [breakpoint_line ])
4554 self .continue_to_next_stop ()
4655 self .continue_to_exit ()
@@ -108,3 +117,47 @@ def test_server_interrupt(self):
108117 self .dap_server .exit_status ,
109118 "Process exited before interrupting lldb-dap server" ,
110119 )
120+
121+ @skipIfWindows
122+ def test_connection_timeout_at_server_start (self ):
123+ """
124+ Test launching lldb-dap in server mode with connection timeout and waiting for it to terminate automatically when no client connects.
125+ """
126+ self .build ()
127+ self .start_server (
128+ connection = "listen://localhost:0" ,
129+ connection_timeout = 1 ,
130+ wait_seconds_for_termination = 2 ,
131+ )
132+
133+ @skipIfWindows
134+ def test_connection_timeout_long_debug_session (self ):
135+ """
136+ Test launching lldb-dap in server mode with connection timeout and terminating the server after the a long debug session.
137+ """
138+ self .build ()
139+ (_ , connection ) = self .start_server (
140+ connection = "listen://localhost:0" ,
141+ connection_timeout = 1 ,
142+ wait_seconds_for_termination = 2 ,
143+ )
144+ # The connection timeout should not cut off the debug session
145+ self .run_debug_session (connection , "Alice" , 1.5 )
146+
147+ @skipIfWindows
148+ def test_connection_timeout_multiple_sessions (self ):
149+ """
150+ Test launching lldb-dap in server mode with connection timeout and terminating the server after the last debug session.
151+ """
152+ self .build ()
153+ (_ , connection ) = self .start_server (
154+ connection = "listen://localhost:0" ,
155+ connection_timeout = 1 ,
156+ wait_seconds_for_termination = 2 ,
157+ )
158+ time .sleep (0.5 )
159+ # Should be able to connect to the server.
160+ self .run_debug_session (connection , "Alice" )
161+ time .sleep (0.5 )
162+ # Should be able to connect to the server, because it's still within the connection timeout.
163+ self .run_debug_session (connection , "Bob" )
0 commit comments