-
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.
Add basic implementation of abandoning parent test
Just check that we have the correct number of processes Fixes #44
- Loading branch information
Showing
1 changed file
with
29 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,29 @@ | ||
from __future__ import annotations | ||
import json | ||
from pathlib import Path | ||
import subprocess | ||
|
||
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) | ||
|
||
|
||
def test_abandoning_parent(temp_output_dir: str) -> None: | ||
duct_prefix = f"{temp_output_dir}log_" | ||
num_children = 3 | ||
command = f"duct -p {duct_prefix} {ABANDONING_PARENT} {num_children} sleep 0.1" | ||
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] | ||
|
||
max_processes_sample = {"processes": {}} | ||
for sample in all_samples: | ||
if len(max_processes_sample) < len(sample.get("processes")): | ||
max_processes_sample = sample | ||
|
||
# 1 for each child, 1 for pstree, 1 for parent | ||
assert len(max_processes_sample) == num_children + 2 |