Repository: microsoft/ptvsd

Issue:
Custom event with process information
Basically identical to the standard 'process' event, but custom. Workaround for [this](https://github.com/Microsoft/ptvsd/issues/503#issuecomment-431193971).


Discussion:

Resolving patch:
diff --git a/ptvsd/wrapper.py b/ptvsd/wrapper.py
--- a/ptvsd/wrapper.py
+++ b/ptvsd/wrapper.py
@@ -1529,6 +1529,7 @@ def send_process_event(self, start_method):
             'startMethod': start_method,
         }
         self.send_event('process', **evt)
+        self.send_event('ptvsd_process', **evt)
 
     @async_handler
     def on_threads(self, request, args):
diff --git a/pytests/helpers/session.py b/pytests/helpers/session.py
--- a/pytests/helpers/session.py
+++ b/pytests/helpers/session.py
@@ -361,14 +361,16 @@ def start_debugging(self, freeze=True):
         # The relative ordering of 'process' and 'configurationDone' is not deterministic.
         # (implementation varies depending on whether it's launch or attach, but in any
         # case, it is an implementation detail).
-        start = self.wait_for_next(Event('process') & Response(configurationDone_request))
+        start = self.wait_for_next(Event('process') & Event('ptvsd_process') & Response(configurationDone_request))
 
-        self.expect_new(Event('process', {
+        expected_process_body = {
             'name': ANY.str,
             'isLocalProcess': True,
             'startMethod': 'launch' if self.method == 'launch' else 'attach',
             'systemProcessId': self.pid if self.pid is not None else ANY.int,
-        }))
+        }
+        self.expect_new(Event('process', expected_process_body))
+        self.expect_new(Event('ptvsd_process', expected_process_body))
 
         if not freeze:
             self.proceed()


Test patch:
diff --git a/tests/highlevel/__init__.py b/tests/highlevel/__init__.py
--- a/tests/highlevel/__init__.py
+++ b/tests/highlevel/__init__.py
@@ -280,9 +280,10 @@ def _handshake(self, command, threadnames=None, config=None, requests=None,
 
         if process:
             with self._fix.wait_for_event('process'):
-                with self._fix.wait_for_event('thread'):
-                    if self._pydevd:
-                        self._pydevd.notify_main_thread()
+                with self._fix.wait_for_event('ptvsd_process'):
+                    with self._fix.wait_for_event('thread'):
+                        if self._pydevd:
+                            self._pydevd.notify_main_thread()
 
         if reset:
             self._fix.reset()
diff --git a/tests/highlevel/test_lifecycle.py b/tests/highlevel/test_lifecycle.py
--- a/tests/highlevel/test_lifecycle.py
+++ b/tests/highlevel/test_lifecycle.py
@@ -78,7 +78,7 @@ def attach(self, expected_os_id, attach_args):
                 req_attach = self.send_request('attach', attach_args)
 
             # configuration
-            with self._fix.wait_for_events(['process']):
+            with self._fix.wait_for_events(['process', 'ptvsd_process']):
                 req_config = self.send_request('configurationDone')
 
             # Normal ops would go here.
@@ -108,6 +108,12 @@ def attach(self, expected_os_id, attach_args):
                isLocalProcess=True,
                startMethod='attach',
             )),
+            self.new_event('ptvsd_process', **dict(
+               name=sys.argv[0],
+               systemProcessId=os.getpid(),
+               isLocalProcess=True,
+               startMethod='attach',
+            )),
         ])
         self.assert_received(self.debugger, [
             self.debugger_msgs.new_request(CMD_VERSION,
diff --git a/tests/highlevel/test_live_pydevd.py b/tests/highlevel/test_live_pydevd.py
--- a/tests/highlevel/test_live_pydevd.py
+++ b/tests/highlevel/test_live_pydevd.py
@@ -165,6 +165,14 @@ def test_launch(self):
                         isLocalProcess=True,
                         startMethod='attach',
                     )),
+                self.new_event(
+                    'ptvsd_process',
+                    **dict(
+                        name=sys.argv[0],
+                        systemProcessId=os.getpid(),
+                        isLocalProcess=True,
+                        startMethod='attach',
+                    )),
                 self.new_event('thread', reason='started', threadId=1),
                 #self.new_event('exited', exitCode=0),
                 #self.new_event('terminated'),
@@ -509,6 +517,14 @@ def test_basic(self):
                     isLocalProcess=True,
                     startMethod='attach',
                 )),
+            self.new_event(
+                'ptvsd_process',
+                **dict(
+                    name=sys.argv[0],
+                    systemProcessId=os.getpid(),
+                    isLocalProcess=True,
+                    startMethod='attach',
+                )),
             self.new_event('thread', reason='started', threadId=1),
             self.new_event(
                 'output',
diff --git a/tests/highlevel/test_messages.py b/tests/highlevel/test_messages.py
--- a/tests/highlevel/test_messages.py
+++ b/tests/highlevel/test_messages.py
@@ -2403,6 +2403,12 @@ def test_launched(self):
                 isLocalProcess=True,
                 startMethod='launch',
             )),
+            self.new_event('ptvsd_process', **dict(
+                name=sys.argv[0],
+                systemProcessId=os.getpid(),
+                isLocalProcess=True,
+                startMethod='launch',
+            )),
             self.expected_event(
                 reason='started',
                 threadId=tid,
@@ -2424,6 +2430,12 @@ def test_attached(self):
                 isLocalProcess=True,
                 startMethod='attach',
             )),
+            self.new_event('ptvsd_process', **dict(
+                name=sys.argv[0],
+                systemProcessId=os.getpid(),
+                isLocalProcess=True,
+                startMethod='attach',
+            )),
             self.expected_event(
                 reason='started',
                 threadId=tid,
@@ -2445,6 +2457,12 @@ def test_process_one_off(self):
                 isLocalProcess=True,
                 startMethod='launch',
             )),
+            self.new_event('ptvsd_process', **dict(
+                name=sys.argv[0],
+                systemProcessId=os.getpid(),
+                isLocalProcess=True,
+                startMethod='launch',
+            )),
             self.expected_event(
                 reason='started',
                 threadId=tid1,
diff --git a/tests/system_tests/test_main.py b/tests/system_tests/test_main.py
--- a/tests/system_tests/test_main.py
+++ b/tests/system_tests/test_main.py
@@ -129,7 +129,7 @@ def test_launch_ptvsd_client(self):
         # Skipping the "thread exited" and "terminated" messages which
         # may appear randomly in the received list.
         received = list(_strip_newline_output_events(session.received))
-        self.assert_received(received[:7], [
+        self.assert_received(received[:8], [
             self.new_version_event(session.received),
             self.new_response(req_initialize.req, **INITIALIZE_RESPONSE),
             self.new_event('initialized'),
@@ -141,6 +141,12 @@ def test_launch_ptvsd_client(self):
                 'startMethod': 'launch',
                 'name': filename,
             }),
+            self.new_event('ptvsd_process', **{
+                'isLocalProcess': True,
+                'systemProcessId': adapter.pid,
+                'startMethod': 'launch',
+                'name': filename,
+            }),
             self.new_event('thread', reason='started', threadId=1),
         ])
 
@@ -162,7 +168,7 @@ def test_launch_ptvsd_server(self):
             adapter.wait()
 
         received = list(_strip_newline_output_events(session.received))
-        self.assert_received(received[:7], [
+        self.assert_received(received[:8], [
             self.new_version_event(session.received),
             self.new_response(req_initialize.req, **INITIALIZE_RESPONSE),
             self.new_event('initialized'),
@@ -174,6 +180,12 @@ def test_launch_ptvsd_server(self):
                 'startMethod': 'launch',
                 'name': filename,
             }),
+            self.new_event('ptvsd_process', **{
+                'isLocalProcess': True,
+                'systemProcessId': adapter.pid,
+                'startMethod': 'launch',
+                'name': filename,
+            }),
             self.new_event('thread', reason='started', threadId=1),
             #self.new_event('thread', reason='exited', threadId=1),
             #self.new_event('exited', exitCode=0),
@@ -197,7 +209,7 @@ def test_attach_started_separately(self):
                 adapter.wait()
 
         received = list(_strip_newline_output_events(session.received))
-        self.assert_received(received[:7], [
+        self.assert_received(received[:8], [
             self.new_version_event(session.received),
             self.new_response(req_initialize.req, **INITIALIZE_RESPONSE),
             self.new_event('initialized'),
@@ -209,6 +221,12 @@ def test_attach_started_separately(self):
                 'startMethod': 'attach',
                 'name': filename,
             }),
+            self.new_event('ptvsd_process', **{
+                'isLocalProcess': True,
+                'systemProcessId': adapter.pid,
+                'startMethod': 'attach',
+                'name': filename,
+            }),
             self.new_event('thread', reason='started', threadId=1),
             #self.new_event('thread', reason='exited', threadId=1),
             #self.new_event('exited', exitCode=0),
@@ -265,6 +283,12 @@ def test_attach_embedded(self):
                 'startMethod': 'attach',
                 'name': filename,
             }),
+            self.new_event('ptvsd_process', **{
+                'isLocalProcess': True,
+                'systemProcessId': adapter.pid,
+                'startMethod': 'attach',
+                'name': filename,
+            }),
             self.new_event('output', output='success!', category='stdout'),
             self.new_event('exited', exitCode=0),
             self.new_event('terminated'),
@@ -314,6 +338,12 @@ def test_reattach(self):
                 'startMethod': 'attach',
                 'name': filename,
             }),
+            self.new_event('ptvsd_process', **{
+                'isLocalProcess': True,
+                'systemProcessId': adapter.pid,
+                'startMethod': 'attach',
+                'name': filename,
+            }),
             self.new_event('thread', reason='started', threadId=1),
             self.new_response(req_disconnect.req),
         ])
@@ -332,6 +362,12 @@ def test_reattach(self):
                 'startMethod': 'attach',
                 'name': filename,
             }),
+            self.new_event('ptvsd_process', **{
+                'isLocalProcess': True,
+                'systemProcessId': adapter.pid,
+                'startMethod': 'attach',
+                'name': filename,
+            }),
             self.new_event('exited', exitCode=0),
             self.new_event('terminated'),
         ])
@@ -451,6 +487,12 @@ def test_detach_clear_and_resume(self):
                 'startMethod': 'attach',
                 'name': filename,
             }),
+            self.new_event('ptvsd_process', **{
+                'isLocalProcess': True,
+                'systemProcessId': adapter.pid,
+                'startMethod': 'attach',
+                'name': filename,
+            }),
             self.new_response(req_bps.req, **{
                 'breakpoints': [{
                     'id': 1,
@@ -506,6 +548,12 @@ def test_detach_clear_and_resume(self):
                 'startMethod': 'attach',
                 'name': filename,
             }),
+            self.new_event('ptvsd_process', **{
+                'isLocalProcess': True,
+                'systemProcessId': adapter.pid,
+                'startMethod': 'attach',
+                'name': filename,
+            }),
             #self.new_event(
             #    'thread',
             #    threadId=tid2,
@@ -721,6 +769,12 @@ def test_attach_breakpoints(self):
                 'startMethod': 'attach',
                 'name': filename,
             }),
+            self.new_event('ptvsd_process', **{
+                'isLocalProcess': True,
+                'systemProcessId': adapter.pid,
+                'startMethod': 'attach',
+                'name': filename,
+            }),
             self.new_event(
                 'stopped',
                 threadId=tid,