Skip to content

Commit 27296f4

Browse files
binaryaaronclaude
andcommitted
test: preview() in a child forked after a parent preview
Covers the user-facing scenario from #1068 end to end: a sampler-only preview in the parent, then a preview in a fork-started child. Runs in a fresh interpreter like the other fork-safety tests. 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Aaron Gonzales <aagonzales@nvidia.com>
1 parent 6916a47 commit 27296f4

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
from __future__ import annotations
5+
6+
import multiprocessing
7+
import os
8+
import subprocess
9+
import sys
10+
11+
import pytest
12+
13+
# Runs in a fresh interpreter so the forked parent is small and holds only what the
14+
# scenario creates, not whatever earlier tests left in the pytest worker.
15+
_PREVIEW_IN_FORKED_CHILD = """
16+
import multiprocessing
17+
import sys
18+
19+
import data_designer.config as dd
20+
from data_designer.interface import DataDesigner
21+
22+
23+
def preview():
24+
builder = dd.DataDesignerConfigBuilder()
25+
builder.add_column(
26+
dd.SamplerColumnConfig(
27+
name="category",
28+
sampler_type=dd.SamplerType.CATEGORY,
29+
params=dd.CategorySamplerParams(values=["a", "b", "c"]),
30+
)
31+
)
32+
assert len(DataDesigner().preview(builder, num_records=3).dataset) == 3
33+
34+
35+
preview() # the parent starts DataDesigner's background event loop
36+
child = multiprocessing.get_context("fork").Process(target=preview)
37+
child.start()
38+
child.join(timeout=30)
39+
if child.is_alive():
40+
child.kill()
41+
child.join()
42+
sys.exit("forked child hung in preview()")
43+
sys.exit(child.exitcode)
44+
"""
45+
46+
47+
@pytest.mark.skipif("fork" not in multiprocessing.get_all_start_methods(), reason="requires the fork start method")
48+
def test_preview_in_child_forked_after_parent_preview() -> None:
49+
result = subprocess.run(
50+
[sys.executable, "-c", _PREVIEW_IN_FORKED_CHILD],
51+
capture_output=True,
52+
text=True,
53+
timeout=120,
54+
env={**os.environ, "NEMO_TELEMETRY_ENABLED": "false"},
55+
)
56+
assert result.returncode == 0, f"preview() in a forked child failed:\n{result.stderr[-4000:]}"

0 commit comments

Comments
 (0)