Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions caso/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ def ssm_message(self):
# done. In order to get objects correctly serialized we need to convert to JSON,
# then reload the model
serialized_record = json.loads(self.model_dump_json(**opts))
# CPU and Wall duration may be 0 as we are converting float to int when creating
# the record, here we impose at least 1 second to avoid reporting no cpu time
for f in ["CpuDuration", "WallDuration"]:
if f in serialized_record and serialized_record[f] == 0:
serialized_record[f] = 1
aux = [f"{k}: {v}" for k, v in serialized_record.items()]
aux.sort()
return "\n".join(aux)
Expand Down
9 changes: 9 additions & 0 deletions caso/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,15 @@ def valid_cloud_record() -> dict:
return valid_cloud_records_dict[0]


@pytest.fixture()
def zero_cpu_cloud_record() -> caso.record.CloudRecord:
"""Get a fixture for the CloudRecord with 0 cpu and wall time."""
record = caso.record.CloudRecord(**valid_cloud_records_fields[0])
record.cpu_duration = 0
record.wall_duration = 0
return record


@pytest.fixture()
def valid_cloud_records() -> typing.List[dict]:
"""Get a fixture for valid records as a dict."""
Expand Down
7 changes: 7 additions & 0 deletions caso/tests/test_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ def test_cloud_record_custom_cpu(cloud_record):
assert cloud_record.cpu_duration == cpu


def test_cloud_record_zero_cpu(zero_cpu_cloud_record):
"""Test a cloud record with 0 CPU time is correctly rendered."""
ssm_message = zero_cpu_cloud_record.ssm_message()
assert "CpuDuration: 1" in ssm_message
assert "WallDuration: 1" in ssm_message


def test_ip_record(ip_record):
"""Test that an IP record is correctly generated."""
assert isinstance(ip_record.measure_time, datetime.datetime)
Expand Down
Loading