File tree Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -232,6 +232,11 @@ def ssm_message(self):
232232 # done. In order to get objects correctly serialized we need to convert to JSON,
233233 # then reload the model
234234 serialized_record = json .loads (self .model_dump_json (** opts ))
235+ # CPU and Wall duration may be 0 as we are converting float to int when creating
236+ # the record, here we impose at least 1 second to avoid reporting no cpu time
237+ for f in ["CpuDuration" , "WallDuration" ]:
238+ if f in serialized_record and serialized_record [f ] == 0 :
239+ serialized_record [f ] = 1
235240 aux = [f"{ k } : { v } " for k , v in serialized_record .items ()]
236241 aux .sort ()
237242 return "\n " .join (aux )
Original file line number Diff line number Diff line change @@ -335,6 +335,15 @@ def valid_cloud_record() -> dict:
335335 return valid_cloud_records_dict [0 ]
336336
337337
338+ @pytest .fixture ()
339+ def zero_cpu_cloud_record () -> caso .record .CloudRecord :
340+ """Get a fixture for the CloudRecord with 0 cpu and wall time."""
341+ record = caso .record .CloudRecord (** valid_cloud_records_fields [0 ])
342+ record .cpu_duration = 0
343+ record .wall_duration = 0
344+ return record
345+
346+
338347@pytest .fixture ()
339348def valid_cloud_records () -> typing .List [dict ]:
340349 """Get a fixture for valid records as a dict."""
Original file line number Diff line number Diff line change @@ -88,6 +88,13 @@ def test_cloud_record_custom_cpu(cloud_record):
8888 assert cloud_record .cpu_duration == cpu
8989
9090
91+ def test_cloud_record_zero_cpu (zero_cpu_cloud_record ):
92+ """Test a cloud record with 0 CPU time is correctly rendered."""
93+ ssm_message = zero_cpu_cloud_record .ssm_message ()
94+ assert "CpuDuration: 1" in ssm_message
95+ assert "WallDuration: 1" in ssm_message
96+
97+
9198def test_ip_record (ip_record ):
9299 """Test that an IP record is correctly generated."""
93100 assert isinstance (ip_record .measure_time , datetime .datetime )
You can’t perform that action at this time.
0 commit comments