Skip to content

Commit

Permalink
dont assume that all processes will be collected in a single sample
Browse files Browse the repository at this point in the history
  • Loading branch information
asmacdo committed Jan 14, 2025
1 parent 8a6fe6c commit 1b49281
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions test/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import json
from pathlib import Path
import subprocess
from typing import Dict
import pytest

ABANDONING_PARENT = str(Path(__file__).with_name("data") / "abandoning_parent.sh")
Expand All @@ -13,26 +12,19 @@ def test_sanity(temp_output_dir: str) -> None:
subprocess.check_output(command, shell=True)


@pytest.mark.parametrize("num_children", [3, 5, 10, 20])
@pytest.mark.parametrize("num_children", [1, 10, 25, 101])
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.01 --r-i 0.02 -p {duct_prefix} {ABANDONING_PARENT} {num_children} sleep 0.1"
command = f"duct --s-i 0.001 --r-i 0.01 -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: Dict[str, Dict] = {"processes": {}}
all_processes = {}
for sample in all_samples:
if len(max_processes_sample) < len(sample.get("processes")):
max_processes_sample = sample

cmds = [proc["cmd"] for _pid, proc in max_processes_sample["processes"].items()]

# DEBUG
from pprint import pprint

pprint(cmds)
for pid, proc in sample["processes"].items():
all_processes[pid] = proc

# 1 for each child, 1 for pstree, 1 for parent
assert len(max_processes_sample["processes"]) == num_children + 2
assert len(all_processes) == num_children + 2

0 comments on commit 1b49281

Please sign in to comment.