@@ -650,7 +650,8 @@ def test_denial_of_service_prevented_int_to_str(self):
650650 self .assertEqual (len (huge_decimal ), digits )
651651 # Ensuring that we chose a slow enough conversion to measure.
652652 # It takes 0.1 seconds on a Zen based cloud VM in an opt build.
653- if seconds_to_convert < 0.005 :
653+ # Some OSes have a low res 1/64s timer, skip if hard to measure.
654+ if seconds_to_convert < 1 / 64 :
654655 raise unittest .SkipTest ('"slow" conversion took only '
655656 f'{ seconds_to_convert } seconds.' )
656657
@@ -662,7 +663,7 @@ def test_denial_of_service_prevented_int_to_str(self):
662663 str (huge_int )
663664 seconds_to_fail_huge = get_time () - start
664665 self .assertIn ('conversion' , str (err .exception ))
665- self .assertLess (seconds_to_fail_huge , seconds_to_convert / 8 )
666+ self .assertLessEqual (seconds_to_fail_huge , seconds_to_convert / 2 )
666667
667668 # Now we test that a conversion that would take 30x as long also fails
668669 # in a similarly fast fashion.
@@ -673,7 +674,7 @@ def test_denial_of_service_prevented_int_to_str(self):
673674 str (extra_huge_int )
674675 seconds_to_fail_extra_huge = get_time () - start
675676 self .assertIn ('conversion' , str (err .exception ))
676- self .assertLess (seconds_to_fail_extra_huge , seconds_to_convert / 8 )
677+ self .assertLess (seconds_to_fail_extra_huge , seconds_to_convert / 2 )
677678
678679 def test_denial_of_service_prevented_str_to_int (self ):
679680 """Regression test: ensure we fail before performing O(N**2) work."""
@@ -691,7 +692,8 @@ def test_denial_of_service_prevented_str_to_int(self):
691692 seconds_to_convert = get_time () - start
692693 # Ensuring that we chose a slow enough conversion to measure.
693694 # It takes 0.1 seconds on a Zen based cloud VM in an opt build.
694- if seconds_to_convert < 0.005 :
695+ # Some OSes have a low res 1/64s timer, skip if hard to measure.
696+ if seconds_to_convert < 1 / 64 :
695697 raise unittest .SkipTest ('"slow" conversion took only '
696698 f'{ seconds_to_convert } seconds.' )
697699
@@ -701,7 +703,7 @@ def test_denial_of_service_prevented_str_to_int(self):
701703 int (huge )
702704 seconds_to_fail_huge = get_time () - start
703705 self .assertIn ('conversion' , str (err .exception ))
704- self .assertLess (seconds_to_fail_huge , seconds_to_convert / 8 )
706+ self .assertLessEqual (seconds_to_fail_huge , seconds_to_convert / 2 )
705707
706708 # Now we test that a conversion that would take 30x as long also fails
707709 # in a similarly fast fashion.
@@ -712,7 +714,7 @@ def test_denial_of_service_prevented_str_to_int(self):
712714 int (extra_huge )
713715 seconds_to_fail_extra_huge = get_time () - start
714716 self .assertIn ('conversion' , str (err .exception ))
715- self .assertLess (seconds_to_fail_extra_huge , seconds_to_convert / 8 )
717+ self .assertLessEqual (seconds_to_fail_extra_huge , seconds_to_convert / 2 )
716718
717719 def test_power_of_two_bases_unlimited (self ):
718720 """The limit does not apply to power of 2 bases."""
0 commit comments