Skip to content

Commit

Permalink
Merge pull request #226 from asmacdo/test-abandoning-parent
Browse files Browse the repository at this point in the history
Test abandoning parent
  • Loading branch information
yarikoptic authored Jan 22, 2025
2 parents 4fae788 + 9074a96 commit dfc3e4d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
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

0 comments on commit dfc3e4d

Please sign in to comment.