Skip to content

Commit

Permalink
Add tests for max value update
Browse files Browse the repository at this point in the history
  • Loading branch information
asmacdo committed Jun 4, 2024
1 parent b98d6b0 commit 6b85116
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/duct.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __init__(
self.arguments = arguments
self.session_id = session_id
self.gpus = []
self.env = None
self.number = 0
self.system_info = {}
self.output_prefix = output_prefix
Expand Down Expand Up @@ -103,13 +104,14 @@ def get_system_info(self):
except subprocess.CalledProcessError:
self.gpus = ["Failed to query GPU info"]

def update_max_resources(self, maxes, sample):
@staticmethod
def update_max_resources(maxes, sample):
for pid in sample:
if pid in maxes:
for key, value in sample[pid].items():
maxes[pid][key] = max(maxes[pid].get(key, value), value)
else:
maxes[pid] = sample[pid]
maxes[pid] = sample[pid].copy()

def collect_sample(self):
process_data = {}
Expand Down
2 changes: 0 additions & 2 deletions test/test_aggregation.py

This file was deleted.

37 changes: 37 additions & 0 deletions test/test_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from collections import defaultdict
from duct import Report

ex0 = {"pid1": {"pcpu": 0.0}}
ex1 = {"pid1": {"pcpu": 1.0}}
ex2 = {"pid2": {"pcpu": 1.0}}
ex2pids = {"pid1": {"pcpu": 0.0}, "pid2": {"pcpu": 0.0}}


def test_update_max_resources_initial_values_one_pid():
maxes = defaultdict(dict)
Report.update_max_resources(maxes, ex0)
assert maxes == ex0


def test_update_max_resources_max_values_one_pid():
maxes = defaultdict(dict)
Report.update_max_resources(maxes, ex0)
Report.update_max_resources(maxes, ex1)
assert maxes == ex1


def test_update_max_resources_initial_values_two_pids():
maxes = defaultdict(dict)
Report.update_max_resources(maxes, ex2pids)
assert maxes == ex2pids


def test_update_max_resources_max_update_values_two_pids():
maxes = defaultdict(dict)
Report.update_max_resources(maxes, ex2pids)
Report.update_max_resources(maxes, ex1)
Report.update_max_resources(maxes, ex2)
assert maxes.keys() == ex2pids.keys()
assert maxes != ex2pids
assert maxes["pid1"] == ex1["pid1"]
assert maxes["pid2"] == ex2["pid2"]

0 comments on commit 6b85116

Please sign in to comment.