[Python-checkins] [3.7] gh-96710: Make the test timing more lenient for the int/str DoS regression test. (GH-96717) (#98195)

ambv webhook-mailer at python.org
Tue Oct 11 17:14:11 EDT 2022


https://github.com/python/cpython/commit/e7fe11186504ec59937a3364cf62e76848d32361
commit: e7fe11186504ec59937a3364cf62e76848d32361
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2022-10-11T23:14:05+02:00
summary:

[3.7] gh-96710: Make the test timing more lenient for the int/str DoS regression test. (GH-96717) (#98195)

gh-96710: Make the test timing more lenient for the int/str DoS regression test. (GH-96717)

A regression would still absolutely fail and even a flaky pass isn't
harmful as it'd fail most of the time across our N system test runs.

Windows has a low resolution timer and CI systems are prone to odd
timing so this just gives more leeway to avoid flakiness.
(cherry picked from commit 11e3548fd1d3445ccde971d613633b58d73c3016)

Co-authored-by: Gregory P. Smith <greg at krypto.org>

files:
M Lib/test/test_int.py

diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py
index 98ba847e7d00..436d2df4ca88 100644
--- a/Lib/test/test_int.py
+++ b/Lib/test/test_int.py
@@ -589,7 +589,8 @@ def test_denial_of_service_prevented_int_to_str(self):
         self.assertEqual(len(huge_decimal), digits)
         # Ensuring that we chose a slow enough conversion to measure.
         # It takes 0.1 seconds on a Zen based cloud VM in an opt build.
-        if seconds_to_convert < 0.005:
+        # Some OSes have a low res 1/64s timer, skip if hard to measure.
+        if seconds_to_convert < 1/64:
             raise unittest.SkipTest('"slow" conversion took only '
                                     f'{seconds_to_convert} seconds.')
 
@@ -601,7 +602,7 @@ def test_denial_of_service_prevented_int_to_str(self):
                 str(huge_int)
             seconds_to_fail_huge = get_time() - start
         self.assertIn('conversion', str(err.exception))
-        self.assertLess(seconds_to_fail_huge, seconds_to_convert/8)
+        self.assertLessEqual(seconds_to_fail_huge, seconds_to_convert/2)
 
         # Now we test that a conversion that would take 30x as long also fails
         # in a similarly fast fashion.
@@ -612,7 +613,7 @@ def test_denial_of_service_prevented_int_to_str(self):
             str(extra_huge_int)
         seconds_to_fail_extra_huge = get_time() - start
         self.assertIn('conversion', str(err.exception))
-        self.assertLess(seconds_to_fail_extra_huge, seconds_to_convert/8)
+        self.assertLess(seconds_to_fail_extra_huge, seconds_to_convert/2)
 
     def test_denial_of_service_prevented_str_to_int(self):
         """Regression test: ensure we fail before performing O(N**2) work."""
@@ -630,7 +631,8 @@ def test_denial_of_service_prevented_str_to_int(self):
         seconds_to_convert = get_time() - start
         # Ensuring that we chose a slow enough conversion to measure.
         # It takes 0.1 seconds on a Zen based cloud VM in an opt build.
-        if seconds_to_convert < 0.005:
+        # Some OSes have a low res 1/64s timer, skip if hard to measure.
+        if seconds_to_convert < 1/64:
             raise unittest.SkipTest('"slow" conversion took only '
                                     f'{seconds_to_convert} seconds.')
 
@@ -640,7 +642,7 @@ def test_denial_of_service_prevented_str_to_int(self):
                 int(huge)
             seconds_to_fail_huge = get_time() - start
         self.assertIn('conversion', str(err.exception))
-        self.assertLess(seconds_to_fail_huge, seconds_to_convert/8)
+        self.assertLessEqual(seconds_to_fail_huge, seconds_to_convert/2)
 
         # Now we test that a conversion that would take 30x as long also fails
         # in a similarly fast fashion.
@@ -651,7 +653,7 @@ def test_denial_of_service_prevented_str_to_int(self):
             int(extra_huge)
         seconds_to_fail_extra_huge = get_time() - start
         self.assertIn('conversion', str(err.exception))
-        self.assertLess(seconds_to_fail_extra_huge, seconds_to_convert/8)
+        self.assertLessEqual(seconds_to_fail_extra_huge, seconds_to_convert/2)
 
     def test_power_of_two_bases_unlimited(self):
         """The limit does not apply to power of 2 bases."""



More information about the Python-checkins mailing list