Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test abandoning parent #226

Merged
merged 12 commits into from
Jan 22, 2025
23 changes: 23 additions & 0 deletions test/data/abandoning_parent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

nchildren=$1
shift

for i in `seq 1 $nchildren`; do
"$@" &
done

echo "Started $nchildren for $$"
# Can be useful when running manually, but commented out so we can count pids in tests
# pstree -c -p "$$"

echo "Starting one more in subprocess"

( "$@" & )

jobs

# Can be useful when running manually, but commented out so we can count pids in tests
# pstree -c -p "$$"
echo "waiting"
wait
28 changes: 28 additions & 0 deletions test/test_e2e.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from __future__ import annotations
from itertools import chain
import json
from pathlib import Path
import subprocess
import pytest

ABANDONING_PARENT = str(Path(__file__).with_name("data") / "abandoning_parent.sh")


def test_sanity(temp_output_dir: str) -> None:
command = f"duct -p {temp_output_dir}log_ sleep 0.1"
subprocess.check_output(command, shell=True)


@pytest.mark.parametrize("num_children", [1, 2, 10])
def test_abandoning_parent(temp_output_dir: str, num_children: int) -> None:
duct_prefix = f"{temp_output_dir}log_"
command = f"duct --s-i 0.001 --r-i 0.01 -p {duct_prefix} {ABANDONING_PARENT} {num_children} sleep 0.2"
subprocess.check_output(command, shell=True)

with open(f"{duct_prefix}usage.json") as usage_file:
all_samples = [json.loads(line) for line in usage_file]

all_pids = set(chain.from_iterable(sample["processes"] for sample in all_samples))

# 1 for each child, 1 for pstree, 1 for parent
assert len(all_pids) == num_children + 2
Loading