mirror of
https://github.com/microsoft/debugpy.git
synced 2025-12-23 08:48:12 +00:00
Wait for socket server before connecting in Tests (#565)
* Wait for socket server * wait for process event * remove debug statements
This commit is contained in:
parent
3edc26db91
commit
83cad60ab4
3 changed files with 11 additions and 7 deletions
|
|
@ -75,14 +75,14 @@ def _copy_env(verbose=False, env=None):
|
|||
return variables
|
||||
|
||||
|
||||
def _wait_for_socket_server(addr, timeout=3.0, **kwargs):
|
||||
def wait_for_socket_server(addr, timeout=3.0, **kwargs):
|
||||
start_time = time.time()
|
||||
while True:
|
||||
try:
|
||||
sock = socket.create_connection(addr)
|
||||
sock = socket.create_connection((addr.host, addr.port))
|
||||
sock.close()
|
||||
return
|
||||
except ConnectionRefusedError:
|
||||
except Exception:
|
||||
pass
|
||||
time.sleep(0.1)
|
||||
if time.time() - start_time > timeout:
|
||||
|
|
@ -151,7 +151,9 @@ class DebugAdapter(Closeable):
|
|||
@classmethod
|
||||
def start_for_attach(cls, addr, *args, **kwargs):
|
||||
addr = Address.as_server(*addr)
|
||||
return cls._start_as(addr, *args, server=True, **kwargs)
|
||||
adapter = cls._start_as(addr, *args, server=True, **kwargs)
|
||||
wait_for_socket_server(addr)
|
||||
return adapter
|
||||
|
||||
@classmethod
|
||||
def _start_as(cls, addr, name, kind='script', extra=None, server=False,
|
||||
|
|
@ -182,7 +184,7 @@ class DebugAdapter(Closeable):
|
|||
addr=addr,
|
||||
**kwargs
|
||||
)
|
||||
_wait_for_socket_server(addr, **kwargs)
|
||||
wait_for_socket_server(addr, **kwargs)
|
||||
return adapter
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import warnings
|
|||
from ptvsd.socket import Address
|
||||
from ptvsd._util import new_hidden_thread
|
||||
from . import Closeable
|
||||
from .debugadapter import DebugAdapter
|
||||
from .debugadapter import DebugAdapter, wait_for_socket_server
|
||||
from .debugsession import DebugSession
|
||||
|
||||
|
||||
|
|
@ -116,6 +116,7 @@ class _LifecycleClient(Closeable):
|
|||
if wait_for_connect:
|
||||
wait_for_connect()
|
||||
else:
|
||||
wait_for_socket_server(addr)
|
||||
self._attach(addr, **kwargs)
|
||||
|
||||
def _attach(self, addr, **kwargs):
|
||||
|
|
|
|||
|
|
@ -64,7 +64,8 @@ class LifecycleTests(HighlevelTest, unittest.TestCase):
|
|||
req_attach = self.send_request('attach', attach_args)
|
||||
|
||||
# configuration
|
||||
req_config = self.send_request('configurationDone')
|
||||
with self._fix.wait_for_events(['process']):
|
||||
req_config = self.send_request('configurationDone')
|
||||
|
||||
# Normal ops would go here.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue