diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-09-09 20:13:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-09 20:13:45 (GMT) |
commit | 5a17200022eef19ea8a5594ebc440974b890238e (patch) | |
tree | 37f841f906be0bd1e9aac580c9020d7d83fdffc3 | |
parent | f60bbf0a933259ece9de8fbe00d08e2dfa795f80 (diff) | |
download | cpython-5a17200022eef19ea8a5594ebc440974b890238e.zip cpython-5a17200022eef19ea8a5594ebc440974b890238e.tar.gz cpython-5a17200022eef19ea8a5594ebc440974b890238e.tar.bz2 |
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@krypto.org>
-rw-r--r-- | Lib/test/test_int.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py index a578ca8..4939d7b 100644 --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -641,7 +641,8 @@ class IntStrDigitLimitsTests(unittest.TestCase): 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.') @@ -653,7 +654,7 @@ class IntStrDigitLimitsTests(unittest.TestCase): 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. @@ -664,7 +665,7 @@ class IntStrDigitLimitsTests(unittest.TestCase): 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.""" @@ -682,7 +683,8 @@ class IntStrDigitLimitsTests(unittest.TestCase): 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.') @@ -692,7 +694,7 @@ class IntStrDigitLimitsTests(unittest.TestCase): 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. @@ -703,7 +705,7 @@ class IntStrDigitLimitsTests(unittest.TestCase): 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.""" |