Add test for wait_for_client.cancel()

This commit is contained in:
Pavel Minaev 2022-05-20 15:12:24 -07:00 committed by Pavel Minaev
parent eb126910c0
commit b0b8db12a5
2 changed files with 41 additions and 2 deletions

View file

@ -28,7 +28,7 @@ def _api(cancelable=False):
from debugpy.server import api
wrapped = getattr(api, f.__name__)
wrapped(*args, **kwargs)
return wrapped(*args, **kwargs)
if cancelable:
@ -36,7 +36,7 @@ def _api(cancelable=False):
from debugpy.server import api
wrapped = getattr(api, f.__name__)
wrapped.cancel(*args, **kwargs)
return wrapped.cancel(*args, **kwargs)
wrapper.cancel = cancel

View file

@ -209,3 +209,42 @@ def test_attach_pid_client(pyfile, target, pid_type):
)
session2.scratchpad["exit"] = True
session2.request_continue()
def test_cancel_wait(pyfile):
@pyfile
def code_to_debug():
import debuggee
import debugpy
import sys
import threading
import time
from debuggee import backchannel
def cancel():
time.sleep(1)
debugpy.wait_for_client.cancel()
_, host, port = sys.argv
port = int(port)
debugpy.listen(address=(host, port))
threading.Thread(target=cancel).start()
debugpy.wait_for_client()
backchannel.send("exit")
with debug.Session() as session:
host, port = runners.attach_connect.host, runners.attach_connect.port
session.config.update({"connect": {"host": host, "port": port}})
session.expected_exit_code = None
backchannel = session.open_backchannel()
session.spawn_debuggee(
[
code_to_debug,
host,
port,
]
)
assert backchannel.receive() == "exit"