@@ -650,7 +650,8 @@ def test_denial_of_service_prevented_int_to_str(self):
650
650
self .assertEqual (len (huge_decimal ), digits )
651
651
# Ensuring that we chose a slow enough conversion to measure.
652
652
# 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 :
654
655
raise unittest .SkipTest ('"slow" conversion took only '
655
656
f'{ seconds_to_convert } seconds.' )
656
657
@@ -662,7 +663,7 @@ def test_denial_of_service_prevented_int_to_str(self):
662
663
str (huge_int )
663
664
seconds_to_fail_huge = get_time () - start
664
665
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 )
666
667
667
668
# Now we test that a conversion that would take 30x as long also fails
668
669
# in a similarly fast fashion.
@@ -673,7 +674,7 @@ def test_denial_of_service_prevented_int_to_str(self):
673
674
str (extra_huge_int )
674
675
seconds_to_fail_extra_huge = get_time () - start
675
676
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 )
677
678
678
679
def test_denial_of_service_prevented_str_to_int (self ):
679
680
"""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):
691
692
seconds_to_convert = get_time () - start
692
693
# Ensuring that we chose a slow enough conversion to measure.
693
694
# 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 :
695
697
raise unittest .SkipTest ('"slow" conversion took only '
696
698
f'{ seconds_to_convert } seconds.' )
697
699
@@ -701,7 +703,7 @@ def test_denial_of_service_prevented_str_to_int(self):
701
703
int (huge )
702
704
seconds_to_fail_huge = get_time () - start
703
705
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 )
705
707
706
708
# Now we test that a conversion that would take 30x as long also fails
707
709
# in a similarly fast fashion.
@@ -712,7 +714,7 @@ def test_denial_of_service_prevented_str_to_int(self):
712
714
int (extra_huge )
713
715
seconds_to_fail_extra_huge = get_time () - start
714
716
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 )
716
718
717
719
def test_power_of_two_bases_unlimited (self ):
718
720
"""The limit does not apply to power of 2 bases."""
0 commit comments