From 26cc6b0a3de4afb1086f60db80405f45dde88d10 Mon Sep 17 00:00:00 2001 From: Pavel Minaev Date: Fri, 25 Jan 2019 17:48:56 -0800 Subject: [PATCH] Assorted test fixes for the Azure automated test run. (#1123) --- pytest.ini | 2 +- src/ptvsd/wrapper.py | 53 +++++++++++++++++++++++++--------------- tests/helpers/session.py | 9 ++++--- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/pytest.ini b/pytest.ini index 6e82adb0..229013d7 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,5 +1,5 @@ [pytest] testpaths=tests -timeout=15 +timeout=30 timeout_method=thread addopts=-n8 diff --git a/src/ptvsd/wrapper.py b/src/ptvsd/wrapper.py index 2fe924c0..3729c716 100644 --- a/src/ptvsd/wrapper.py +++ b/src/ptvsd/wrapper.py @@ -698,37 +698,50 @@ class ModulesManager(object): pass search_path = self._get_platform_file_path(module_path) + for _, value in list(sys.modules.items()): try: path = self._get_platform_file_path(value.__file__) except AttributeError: path = None - if path and search_path == path: - module_id = self._next_id - self._next_id += 1 + if not path: + continue - module = { - 'id': module_id, - 'package': value.__package__ if hasattr(value, '__package__') else None, - 'path': module_path, - } + try: + # This tries to open the files to obtain handles, which can be restricted + # by file permissions, but ensures that long/short path mismatch, symlinks + # etc are all accounted for. Fall back to comparing names in case of failure. + if not os.path.samefile(path, search_path): + continue + except Exception: + if path != search_path: + continue - try: - module['name'] = value.__qualname__ - except AttributeError: - module['name'] = value.__name__ + module_id = self._next_id + self._next_id += 1 - try: - module['version'] = value.__version__ - except AttributeError: - pass + module = { + 'id': module_id, + 'package': value.__package__ if hasattr(value, '__package__') else None, + 'path': module_path, + } - self.path_to_module_id[module_path] = module_id - self.module_id_to_details[module_id] = module + try: + module['name'] = value.__qualname__ + except AttributeError: + module['name'] = value.__name__ - self.proc.send_event('module', reason='new', module=module) - return module + try: + module['version'] = value.__version__ + except AttributeError: + pass + + self.path_to_module_id[module_path] = module_id + self.module_id_to_details[module_id] = module + + self.proc.send_event('module', reason='new', module=module) + return module return None diff --git a/tests/helpers/session.py b/tests/helpers/session.py index 472771fb..feac4b7e 100644 --- a/tests/helpers/session.py +++ b/tests/helpers/session.py @@ -20,7 +20,7 @@ import ptvsd.__main__ from ptvsd.messaging import JsonIOStream, JsonMessageChannel, MessageHandlers import tests.helpers -from . import colors, debuggee, print, watchdog +from . import colors, debuggee, print from .messaging import LoggingJsonStream from .pattern import ANY from .printer import wait_for_output @@ -34,8 +34,8 @@ PTVSD_PORT_KEY = 'PTVSD_TEST_PORT' class DebugSession(object): - WAIT_FOR_EXIT_TIMEOUT = 5 - BACKCHANNEL_TIMEOUT = 15 + WAIT_FOR_EXIT_TIMEOUT = 10 + BACKCHANNEL_TIMEOUT = 20 StopInfo = namedtuple('StopInfo', 'thread_stopped, stacktrace, thread_id, frame_id') @@ -268,7 +268,7 @@ class DebugSession(object): self.pid = self.process.pid self.psutil_process = psutil.Process(self.pid) self.is_running = True - watchdog.create(self.pid) + #watchdog.create(self.pid) self._capture_output(self.process.stdout, 'OUT') self._capture_output(self.process.stderr, 'ERR') @@ -585,6 +585,7 @@ class DebugSession(object): child_session.handshake() except: child_session.close() + raise else: return child_session