From 00b6a202f33411fbba0cad08aba5cb7503eccdb6 Mon Sep 17 00:00:00 2001 From: Pavel Minaev Date: Tue, 21 Jan 2020 17:27:28 -0800 Subject: [PATCH 1/4] Fix test_autokill --- tests/debug/session.py | 2 -- tests/debugpy/test_multiproc.py | 45 +++++++++++---------------------- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/tests/debug/session.py b/tests/debug/session.py index bbadf68b..bbe313bf 100644 --- a/tests/debug/session.py +++ b/tests/debug/session.py @@ -785,8 +785,6 @@ class Session(object): # FIXME: "exited" event is not properly reported in attach scenarios at the # moment, so the exit code is only checked if it's present. - if self.start_request.command == "launch": - assert self.exit_code is not None if self.debuggee is not None and self.exit_code is not None: assert self.debuggee.returncode == self.exit_code return self.exit_code diff --git a/tests/debugpy/test_multiproc.py b/tests/debugpy/test_multiproc.py index 99868e19..064395e1 100644 --- a/tests/debugpy/test_multiproc.py +++ b/tests/debugpy/test_multiproc.py @@ -8,7 +8,6 @@ import pytest import sys import debugpy -from debugpy.common import messaging from tests import debug from tests.debug import runners from tests.patterns import some @@ -207,11 +206,7 @@ def test_subprocess(pyfile, target, run): assert child_argv == [child, "--arg1", "--arg2", "--arg3"] -@pytest.mark.skip("Needs refactoring to use the new debug.Session API") -@pytest.mark.parametrize( - "start_method", [runners.launch, runners.attach_by_socket["cli"]] -) -def test_autokill(pyfile, start_method, run_as): +def test_autokill(pyfile, target): @pyfile def child(): import debug_me # noqa @@ -224,7 +219,6 @@ def test_autokill(pyfile, start_method, run_as): import os import subprocess import sys - from debug_me import backchannel argv = [sys.executable, sys.argv[1]] env = os.environ.copy() @@ -234,32 +228,23 @@ def test_autokill(pyfile, start_method, run_as): stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - ) - backchannel.receive() + ).wait() - with debug.Session(start_method, backchannel=True) as parent_session: - parent_backchannel = parent_session.backchannel - expected_exit_code = ( - some.int if parent_session.start_method.method == "launch" else 0 - ) - parent_session.expected_exit_code = expected_exit_code - parent_session.configure(run_as, parent, subProcess=True, args=[child]) - parent_session.start_debugging() + with debug.Session() as parent_session: + parent_session.expected_exit_code = some.int - with parent_session.attach_to_next_subprocess() as child_session: - child_session.start_debugging() + with parent_session.launch(target(parent, args=[child])): + pass - if parent_session.start_method.method == "launch": - # In launch scenario, terminate the parent process by disconnecting from it. - try: - parent_session.request("disconnect") - except messaging.NoMoreMessages: - # Can happen if debugpy drops connection before sending the response. - pass - parent_session.wait_for_disconnect() - else: - # In attach scenario, just let the parent process run to completion. - parent_backchannel.send(None) + child_config = parent_session.wait_for_next_event("debugpyAttach") + parent_session.proceed() + + with debug.Session(child_config) as child_session: + with child_session.start(): + pass + + parent_session.debuggee.kill() + child_session.wait_for_exit() @pytest.mark.skip("Needs refactoring to use the new debug.Session API") From a45040a4f99cf9e52b44aabc07d3dbd3dad2de27 Mon Sep 17 00:00:00 2001 From: Pavel Minaev Date: Tue, 21 Jan 2020 17:41:25 -0800 Subject: [PATCH 2/4] Fix test_argv_quoting --- tests/debugpy/test_multiproc.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/debugpy/test_multiproc.py b/tests/debugpy/test_multiproc.py index 064395e1..6d719910 100644 --- a/tests/debugpy/test_multiproc.py +++ b/tests/debugpy/test_multiproc.py @@ -247,8 +247,7 @@ def test_autokill(pyfile, target): child_session.wait_for_exit() -@pytest.mark.skip("Needs refactoring to use the new debug.Session API") -def test_argv_quoting(pyfile, start_method, run_as): +def test_argv_quoting(pyfile, target, run): @pyfile def args(): import debug_me # noqa @@ -289,15 +288,23 @@ def test_argv_quoting(pyfile, start_method, run_as): actual_args = sys.argv[1:] backchannel.send(actual_args) - with debug.Session(start_method, backchannel=True) as session: - backchannel = session.backchannel - session.configure(run_as, parent, args=[child]) + with debug.Session() as parent_session: + backchannel = parent_session.open_backchannel() - session.start_debugging() + with run(parent_session, target(parent, args=[child])): + pass - expected_args = backchannel.receive() - actual_args = backchannel.receive() - assert expected_args == actual_args + child_config = parent_session.wait_for_next_event("debugpyAttach") + parent_session.proceed() + + with debug.Session(child_config) as child_session: + with child_session.start(): + pass + + expected_args = backchannel.receive() + actual_args = backchannel.receive() + + assert expected_args == actual_args @pytest.mark.skip("Needs refactoring to use the new debug.Session API") From c530c29281839fb5f4cd36d6905a0e51fda89150 Mon Sep 17 00:00:00 2001 From: Pavel Minaev Date: Tue, 21 Jan 2020 17:49:02 -0800 Subject: [PATCH 3/4] Fix test_echo_and_shell --- tests/debugpy/test_multiproc.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/debugpy/test_multiproc.py b/tests/debugpy/test_multiproc.py index 6d719910..f955e3be 100644 --- a/tests/debugpy/test_multiproc.py +++ b/tests/debugpy/test_multiproc.py @@ -307,8 +307,7 @@ def test_argv_quoting(pyfile, target, run): assert expected_args == actual_args -@pytest.mark.skip("Needs refactoring to use the new debug.Session API") -def test_echo_and_shell(pyfile, run_as, start_method): +def test_echo_and_shell(pyfile, target, run): """ Checks https://github.com/microsoft/ptvsd/issues/1548 """ @@ -343,6 +342,6 @@ def test_echo_and_shell(pyfile, run_as, start_method): % (stdout,) ) - with debug.Session(start_method) as session: - session.configure(run_as, code_to_run, subProcess=True) - session.start_debugging() + with debug.Session() as parent_session: + with run(parent_session, target(code_to_run)): + pass From ddef96655fc05590781450ec8fe304aeb3000997 Mon Sep 17 00:00:00 2001 From: Pavel Minaev Date: Tue, 21 Jan 2020 21:43:19 -0800 Subject: [PATCH 4/4] Disable test_autokill due to https://github.com/microsoft/debugpy/issues/3 --- tests/debugpy/test_multiproc.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/debugpy/test_multiproc.py b/tests/debugpy/test_multiproc.py index f955e3be..9f075cd4 100644 --- a/tests/debugpy/test_multiproc.py +++ b/tests/debugpy/test_multiproc.py @@ -206,6 +206,7 @@ def test_subprocess(pyfile, target, run): assert child_argv == [child, "--arg1", "--arg2", "--arg3"] +@pytest.mark.skip("https://github.com/microsoft/debugpy/issues/3") def test_autokill(pyfile, target): @pyfile def child():