Skip to content

Commit 64eefe6

Browse files
committed
python test driver: fix capturing of replay files
* Only capture replay files when there are errors * Capture replay files in the working clone rather than in /tmp/, which does not work well on shared machines.
1 parent 9f86c61 commit 64eefe6

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

testsuite/drivers/lsp_python_driver.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ def __init__(
116116
env=env,
117117
)
118118

119+
self.wd = working_dir
120+
119121
# Kill the server when we reach this time
120122
self.kill_me_at = time.time() + RLIMIT_SECONDS * (
121123
1 + os.environ.get("ALS_WAIT_FACTOR", 0))
@@ -177,6 +179,9 @@ def receive_task(self):
177179
if not header.startswith("Content-Length:"):
178180
continue
179181
length = int(header[len("Content-Length:"):])
182+
183+
# TODO: Add support for "Content-Type" header
184+
180185
# Read the JSON message
181186
# (adding +2 to account of \r\n)
182187
content = self.process.stdout.read(length + 2).decode("utf-8")
@@ -246,8 +251,22 @@ def shutdown(self):
246251
# Set the license to kill
247252
self.license_to_kill = time.time()
248253

254+
if not self.errors:
255+
return
256+
257+
# If errors were found, capture a replay file.
258+
# Compute the replay dir based on this file
259+
replay_dir = os.path.join(
260+
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
261+
"replays"
262+
)
263+
# Create the directory if it doesn't exist
264+
os.makedirs(replay_dir, exist_ok=True)
265+
replay_file = os.path.join(replay_dir, os.path.basename(self.wd) + "_replay.txt")
266+
self.errors.append(f"Replay file written to {replay_file}")
267+
249268
# Write a "replay.txt" replay file
250-
with open("/tmp/replay.txt", "wb") as f:
269+
with open(replay_file, "wb") as f:
251270
for message in self.replay:
252271
f.write(message)
253272

@@ -279,12 +298,12 @@ def run_simple_test(test_function, working_dir) -> list[str]:
279298
lsp.shutdown()
280299
return lsp.errors
281300
except Exception as e:
282-
lsp.shutdown()
283-
errors = [str(e)]
301+
lsp.errors += [str(e)]
284302
# If the exception is an AssertionError, no need for the traceback
285303
if not isinstance(e, ResponseAssertionError):
286-
errors.append(traceback.format_exc())
287-
return lsp.errors + errors
304+
lsp.errors.append(traceback.format_exc())
305+
lsp.shutdown()
306+
return lsp.errors
288307

289308

290309
# Make run_simple_test available as a decorator

0 commit comments

Comments
 (0)