@@ -641,7 +641,8 @@ def test_denial_of_service_prevented_int_to_str(self):
641
641
self .assertEqual (len (huge_decimal ), digits )
642
642
# Ensuring that we chose a slow enough conversion to measure.
643
643
# It takes 0.1 seconds on a Zen based cloud VM in an opt build.
644
- if seconds_to_convert < 0.005 :
644
+ # Some OSes have a low res 1/64s timer, skip if hard to measure.
645
+ if seconds_to_convert < 1 / 64 :
645
646
raise unittest .SkipTest ('"slow" conversion took only '
646
647
f'{ seconds_to_convert } seconds.' )
647
648
@@ -653,7 +654,7 @@ def test_denial_of_service_prevented_int_to_str(self):
653
654
str (huge_int )
654
655
seconds_to_fail_huge = get_time () - start
655
656
self .assertIn ('conversion' , str (err .exception ))
656
- self .assertLess (seconds_to_fail_huge , seconds_to_convert / 8 )
657
+ self .assertLessEqual (seconds_to_fail_huge , seconds_to_convert / 2 )
657
658
658
659
# Now we test that a conversion that would take 30x as long also fails
659
660
# in a similarly fast fashion.
@@ -664,7 +665,7 @@ def test_denial_of_service_prevented_int_to_str(self):
664
665
str (extra_huge_int )
665
666
seconds_to_fail_extra_huge = get_time () - start
666
667
self .assertIn ('conversion' , str (err .exception ))
667
- self .assertLess (seconds_to_fail_extra_huge , seconds_to_convert / 8 )
668
+ self .assertLess (seconds_to_fail_extra_huge , seconds_to_convert / 2 )
668
669
669
670
def test_denial_of_service_prevented_str_to_int (self ):
670
671
"""Regression test: ensure we fail before performing O(N**2) work."""
@@ -682,7 +683,8 @@ def test_denial_of_service_prevented_str_to_int(self):
682
683
seconds_to_convert = get_time () - start
683
684
# Ensuring that we chose a slow enough conversion to measure.
684
685
# It takes 0.1 seconds on a Zen based cloud VM in an opt build.
685
- if seconds_to_convert < 0.005 :
686
+ # Some OSes have a low res 1/64s timer, skip if hard to measure.
687
+ if seconds_to_convert < 1 / 64 :
686
688
raise unittest .SkipTest ('"slow" conversion took only '
687
689
f'{ seconds_to_convert } seconds.' )
688
690
@@ -692,7 +694,7 @@ def test_denial_of_service_prevented_str_to_int(self):
692
694
int (huge )
693
695
seconds_to_fail_huge = get_time () - start
694
696
self .assertIn ('conversion' , str (err .exception ))
695
- self .assertLess (seconds_to_fail_huge , seconds_to_convert / 8 )
697
+ self .assertLessEqual (seconds_to_fail_huge , seconds_to_convert / 2 )
696
698
697
699
# Now we test that a conversion that would take 30x as long also fails
698
700
# in a similarly fast fashion.
@@ -703,7 +705,7 @@ def test_denial_of_service_prevented_str_to_int(self):
703
705
int (extra_huge )
704
706
seconds_to_fail_extra_huge = get_time () - start
705
707
self .assertIn ('conversion' , str (err .exception ))
706
- self .assertLess (seconds_to_fail_extra_huge , seconds_to_convert / 8 )
708
+ self .assertLessEqual (seconds_to_fail_extra_huge , seconds_to_convert / 2 )
707
709
708
710
def test_power_of_two_bases_unlimited (self ):
709
711
"""The limit does not apply to power of 2 bases."""
0 commit comments