@@ -33,7 +33,7 @@ def test_ctor_defaults(self):
3333 mock_type = mock .Mock ()
3434 metric = self ._make_one (mock_type )
3535 assert metric .op_type == mock_type
36- assert abs ( metric .start_time_ns - time .monotonic_ns ()) < 1e6 # 1ms buffer
36+ assert metric .start_time_ns == pytest . approx ( time .monotonic_ns (), abs = 50e6 ) # 50 ms buffer
3737 assert metric .active_attempt is None
3838 assert metric .cluster_id is None
3939 assert metric .zone is None
@@ -180,10 +180,10 @@ def test_start(self):
180180 """
181181 orig_time = 0
182182 metric = self ._make_one (mock .Mock (), start_time_ns = orig_time )
183- assert abs ( metric .start_time_ns - time . monotonic_ns ()) > 1e6 # 1ms buffer
183+ assert metric .start_time_ns == 0
184184 metric .start ()
185185 assert metric .start_time_ns != orig_time
186- assert abs ( metric .start_time_ns - time .monotonic_ns ()) < 1e6 # 1ms buffer
186+ assert metric .start_time_ns == pytest . approx ( time .monotonic_ns (), abs = 50e6 )
187187 # should remain in CREATED state after completing
188188 assert metric .state == State .CREATED
189189
@@ -198,9 +198,7 @@ def test_start_attempt(self):
198198 metric .start_attempt ()
199199 assert isinstance (metric .active_attempt , ActiveAttemptMetric )
200200 # make sure it was initialized with the correct values
201- assert (
202- abs (time .monotonic_ns () - metric .active_attempt .start_time_ns ) < 1e6
203- ) # 1ms buffer
201+ assert metric .active_attempt .start_time_ns == pytest .approx (time .monotonic_ns (), abs = 50e6 )
204202 assert metric .active_attempt .gfe_latency_ns is None
205203 assert metric .active_attempt .grpc_throttling_time_ns == 0
206204 # should be in ACTIVE_ATTEMPT state after completing
@@ -414,7 +412,7 @@ def test_end_attempt_with_status(self):
414412 assert len (metric .completed_attempts ) == 1
415413 got_attempt = metric .completed_attempts [0 ]
416414 expected_duration = time .monotonic_ns () - expected_start_time
417- assert abs ( got_attempt .duration_ns - expected_duration ) < 10e6 # within 10ms
415+ assert got_attempt .duration_ns == pytest . approx ( expected_duration , abs = 50e6 )
418416 assert got_attempt .grpc_throttling_time_ns == expected_grpc_throttle
419417 assert got_attempt .end_status == expected_status
420418 assert got_attempt .gfe_latency_ns == expected_gfe_latency_ns
@@ -493,9 +491,7 @@ def test_end_with_status(self):
493491 called_with = h .on_operation_complete .call_args [0 ][0 ]
494492 assert called_with .op_type == expected_type
495493 expected_duration = time .monotonic_ns () - expected_start_time
496- assert (
497- abs (called_with .duration_ns - expected_duration ) < 10e6
498- ) # within 10ms
494+ assert called_with .duration_ns == pytest .approx (expected_duration , abs = 50e6 )
499495 assert called_with .final_status == expected_status
500496 assert called_with .cluster_id == expected_cluster
501497 assert called_with .zone == expected_zone
@@ -511,9 +507,7 @@ def test_end_with_status(self):
511507 assert final_attempt .gfe_latency_ns == expected_attempt_gfe_latency_ns
512508 assert final_attempt .end_status == expected_status
513509 expected_duration = time .monotonic_ns () - expected_attempt_start_time
514- assert (
515- abs (final_attempt .duration_ns - expected_duration ) < 10e6
516- ) # within 10ms
510+ assert final_attempt .duration_ns == pytest .approx (expected_duration , abs = 50e6 )
517511
518512 def test_end_with_status_w_exception (self ):
519513 """
0 commit comments