@@ -648,13 +648,11 @@ def test_denial_of_service_prevented_int_to_str(self):
648
648
huge_decimal = str (huge_int )
649
649
seconds_to_convert = get_time () - start
650
650
self .assertEqual (len (huge_decimal ), digits )
651
- # Ensuring that we chose a slow enough conversion to time.
652
- # Unlikely any CPU core will ever be faster than the assertion.
653
- # It takes 0.10 seconds on a Zen based cloud VM in an opt build.
651
+ # Ensuring that we chose a slow enough conversion to measure.
652
+ # It takes 0.1 seconds on a Zen based cloud VM in an opt build.
654
653
if seconds_to_convert < 0.005 :
655
- raise unittest .SkipTest (f'' )
656
- self .assertGreater (seconds_to_convert , 0.005 ,
657
- msg = "'We're gonna need a bigger boat (int).'" )
654
+ raise unittest .SkipTest ('"slow" conversion took only '
655
+ f'{ seconds_to_convert } seconds.' )
658
656
659
657
# We test with the limit almost at the size needed to check performance.
660
658
# The performant limit check is slightly fuzzy, give it a some room.
@@ -685,18 +683,19 @@ def test_denial_of_service_prevented_str_to_int(self):
685
683
if get_time () <= 0 : # some platforms like WASM lack process_time()
686
684
get_time = time .monotonic
687
685
688
- huge = '8' * 200_000
689
- with support .adjust_int_max_str_digits (200_000 ):
686
+ digits = 133700
687
+ huge = '8' * digits
688
+ with support .adjust_int_max_str_digits (digits ):
690
689
start = get_time ()
691
690
int (huge )
692
691
seconds_to_convert = get_time () - start
693
- # Ensuring that we chose a slow enough conversion to time .
694
- # Unlikely any CPU core will ever be faster than the assertion .
695
- # It takes 0.25 seconds on a Zen based cloud VM in an opt build.
696
- self . assertGreater ( seconds_to_convert , 0.02 ,
697
- msg = "'We're gonna need a bigger boat (str).'" )
692
+ # Ensuring that we chose a slow enough conversion to measure .
693
+ # It takes 0.1 seconds on a Zen based cloud VM in an opt build .
694
+ if seconds_to_convert < 0.005 :
695
+ raise unittest . SkipTest ( '"slow" conversion took only '
696
+ f' { seconds_to_convert } seconds.' )
698
697
699
- with support .adjust_int_max_str_digits (200_000 - 1 ):
698
+ with support .adjust_int_max_str_digits (digits - 1 ):
700
699
with self .assertRaises (ValueError ) as err :
701
700
start = get_time ()
702
701
int (huge )
@@ -709,7 +708,7 @@ def test_denial_of_service_prevented_str_to_int(self):
709
708
extra_huge = '7' * 1_200_000
710
709
with self .assertRaises (ValueError ) as err :
711
710
start = get_time ()
712
- # If not limited, 8 seconds said Zen based cloud VM.
711
+ # If not limited, 8 seconds in the Zen based cloud VM.
713
712
int (extra_huge )
714
713
seconds_to_fail_extra_huge = get_time () - start
715
714
self .assertIn ('conversion' , str (err .exception ))
0 commit comments