Skip to content

Commit 6191052

Browse files
authored
mz-debug: Minor test fix for quick reruns (#37904)
So we don't accidentally reuse an existing file from the same minute. Follow-up to #37816
1 parent 6549653 commit 6191052

1 file changed

Lines changed: 28 additions & 10 deletions

File tree

‎test/mz-debug/mzcompose.py‎

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
E2E tests for mz-debug
1212
"""
1313

14+
import shutil
1415
import urllib.request
1516
from pathlib import Path
1617

@@ -137,12 +138,21 @@ def _assert_cpu_capture_preserves_heap_profile(
137138
)
138139

139140

140-
def _newest_dump_dir() -> Path:
141-
"""Returns the most recently written `mz_debug_<timestamp>` directory in the
142-
working directory, where `mz-debug` writes its output."""
143-
dump_dirs = [p for p in Path.cwd().glob("mz_debug_*") if p.is_dir()]
144-
assert dump_dirs, "mz-debug did not create an mz_debug_* output directory"
145-
return max(dump_dirs, key=lambda p: p.stat().st_mtime)
141+
def _sole_dump_dir(run_dir: Path) -> Path:
142+
"""Returns the single `mz_debug_<timestamp>` directory that an `mz-debug` run
143+
wrote into `run_dir`.
144+
145+
`mz-debug` names its output directory with minute precision, so consecutive
146+
runs share a directory and a later run happily inherits an earlier run's
147+
artifacts. Asserting on one run's output therefore requires giving it an
148+
otherwise empty working directory, and finding more than one directory in
149+
there means the isolation broke.
150+
"""
151+
dump_dirs = sorted(p for p in run_dir.glob("mz_debug_*") if p.is_dir())
152+
assert (
153+
len(dump_dirs) == 1
154+
), f"expected exactly one mz_debug_* output directory in {run_dir}, found {dump_dirs}"
155+
return dump_dirs[0]
146156

147157

148158
def _assert_default_dump_files(dump_dir: Path, container_id: str) -> None:
@@ -197,15 +207,23 @@ def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
197207
_assert_cpu_capture_preserves_heap_profile(c, container_id)
198208

199209
# Smoke test: a full `mz-debug` run against the emulator completes without
200-
# error and produces the complete set of default output files.
210+
# error and produces the complete set of default output files. It runs in an
211+
# empty directory of its own so that it cannot inherit the artifacts of the
212+
# explicitly flagged run above, which enabled CPU profiling and would
213+
# otherwise leave a CPU profile behind in the shared, minute-granular output
214+
# directory.
215+
run_dir = Path("default-run").absolute()
216+
shutil.rmtree(run_dir, ignore_errors=True)
217+
run_dir.mkdir()
201218
spawn.runv(
202219
[
203-
"./mz-debug",
220+
Path("mz-debug").absolute(),
204221
"emulator",
205222
"--docker-container-id",
206223
container_id,
207224
"--mz-connection-url",
208225
"postgres://mz_system@127.0.0.1:6877/materialize",
209-
]
226+
],
227+
cwd=run_dir,
210228
)
211-
_assert_default_dump_files(_newest_dump_dir(), container_id)
229+
_assert_default_dump_files(_sole_dump_dir(run_dir), container_id)

0 commit comments

Comments
 (0)