Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sporadic failures in test_int test_denial_of_service_prevented_str_to_int #118686

Open
tim-one opened this issue May 7, 2024 · 0 comments
Open
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@tim-one
Copy link
Member

tim-one commented May 7, 2024

Bug report

Bug description:

I'm seeing inconsistent failures in test_int's test_denial_of_service_prevented_str_to_int. Typical:

  File "C:\Code\Python\Lib\test\test_int.py", line 738, in test_denial_of_service_prevented_str_to_int
    self.assertLessEqual(sw_fail_extra_huge.seconds, sw_convert.seconds/2)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 0.015625 not less than or equal to 0.0078125

The displayed times are small enough that they're well within the range a non-idle Windows may, at times, essentially not give any cycles to a process.

I expect the underlying cause is that various hard-coded constants in the test were picked when CPython's int<->str conversions, for "large" values, were much slower than they are now. They're no longer quadratic-time. str->int is O(d**1.585) now (inherited from the asymptotics of CPython's Karatsuba multiplicatiom), and int->str the much better O(d * messy expression involving logarithms) (inherited from the asymptotics of _decimal's fancier NTT multiplication) - where d is the number of digits (or bits - same thing to O()).

Comments like:

        # 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.

suggest a cure: don't use hard-coded constants. Instead take a starting guess at the number of digits and keep boosting it until a conversion actually does take 0.1 seconds.

Or don't bother timing it at all 😉. It's already checking that "big" cases raise ValueError with "conversion" in the exception detail message, so it's essentially certain that int() failed before doing any real work.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

@tim-one tim-one added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir labels May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant