Skip to content

Commit 88b3969

Browse files
authored
[lldb-dap] Address a unit test race condition during initialization. (#167981)
During the initialization sequence in our tests the first 'threads' response sould only be kept if the process is actually stopped, otherwise we will have stale data. In VSCode, during the debug session startup sequence immediately after 'configurationDone' a 'threads' request is made. This initial request is to retrieve the main threads name and id so the UI can be populated. However, in our tests we do not want to cache this value unless the process is actually stopped. We do need to make this initial request because lldb-dap is caching the initial thread list during configurationDone before the process is resumed. We need to make this call to ensure the cached initial threads are purged. I noticed this in a CI job for another review (https://github.com/llvm/llvm-project/actions/runs/19348261989/job/55353961798) where the tests incorrectly failed to fetch the threads prior to validating the thread names.
1 parent 6245a4f commit 88b3969

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ class NotSupportedError(KeyError):
191191

192192

193193
class DebugCommunication(object):
194+
@property
195+
def is_stopped(self) -> bool:
196+
"""Returns True if the debuggee is stopped, otherwise False."""
197+
return len(self.thread_stop_reasons) > 0 or self.exit_status is not None
198+
194199
def __init__(
195200
self,
196201
recv: BinaryIO,
@@ -860,7 +865,17 @@ def request_configurationDone(self):
860865
response = self._send_recv(command_dict)
861866
if response:
862867
self.configuration_done_sent = True
868+
stopped_on_entry = self.is_stopped
863869
self.request_threads()
870+
if not stopped_on_entry:
871+
# Drop the initial cached threads if we did not stop-on-entry.
872+
# In VSCode, immediately following 'configurationDone', a
873+
# 'threads' request is made to get the initial set of threads,
874+
# specifically the main threads id and name.
875+
# We issue the threads request to mimic this pattern but in our
876+
# tests we don't want to cache the result unless the process is
877+
# actually stopped.
878+
self.threads = None
864879
return response
865880

866881
def _process_stopped(self):

0 commit comments

Comments
 (0)