Skip to content

Commit 4dae3e0

Browse files
committed
cleanup the test.
skip rather than fail if we find unexpectedly high performance.
1 parent 56f08c2 commit 4dae3e0

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

Lib/test/test_int.py

+14-15
Original file line numberDiff line numberDiff line change
@@ -648,13 +648,11 @@ def test_denial_of_service_prevented_int_to_str(self):
648648
huge_decimal = str(huge_int)
649649
seconds_to_convert = get_time() - start
650650
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.
654653
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.')
658656

659657
# We test with the limit almost at the size needed to check performance.
660658
# 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):
685683
if get_time() <= 0: # some platforms like WASM lack process_time()
686684
get_time = time.monotonic
687685

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):
690689
start = get_time()
691690
int(huge)
692691
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.')
698697

699-
with support.adjust_int_max_str_digits(200_000 - 1):
698+
with support.adjust_int_max_str_digits(digits - 1):
700699
with self.assertRaises(ValueError) as err:
701700
start = get_time()
702701
int(huge)
@@ -709,7 +708,7 @@ def test_denial_of_service_prevented_str_to_int(self):
709708
extra_huge = '7'*1_200_000
710709
with self.assertRaises(ValueError) as err:
711710
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.
713712
int(extra_huge)
714713
seconds_to_fail_extra_huge = get_time() - start
715714
self.assertIn('conversion', str(err.exception))

0 commit comments

Comments
 (0)