-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #226 from asmacdo/test-abandoning-parent
Test abandoning parent
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |