X Tutup
Skip to content

gh-145607: Ensure BIG_DATA has two compressed blocks in test_bz2#145730

Merged
hugovk merged 1 commit intopython:mainfrom
emmatyping:fix-bz2-flake
Mar 10, 2026
Merged

gh-145607: Ensure BIG_DATA has two compressed blocks in test_bz2#145730
hugovk merged 1 commit intopython:mainfrom
emmatyping:fix-bz2-flake

Conversation

@emmatyping
Copy link
Member

@emmatyping emmatyping commented Mar 10, 2026

The BIG_DATA variable in test_bz2 will sometimes only have one block of compressed data instead of the two it is intended to contain due to the value depending on the order of listing files. To fix this, we stream in input data and check for multiple block header magic strings to ensure that there are at least 2 block headers.

This is an unfortunate hack, but the bz2 module doesn't expose flushing in calls to BZ2Compressor.compress() so we cannot directly generate two blocks. I'm also not certain if block headers can span the output to .compress(), so conservatively I have the code scan the entire set of data, which should only need to happen a few times at test setup time. There's probably a few ways to optimize this code, but I wanted to keep it simple to get it in before the alpha tomorrow. I specifically did not want to use BZ2File as I wanted the module setup code to be as minimal as possible in case the implementation is broken.

@emmatyping
Copy link
Member Author

Oh also I ran the test in a loop with random file orderings for a number of minutes to ensure that this actually fixes the bug.

@emmatyping
Copy link
Member Author

!buildbot s390x RHEL9

@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @emmatyping for commit f9e9d59 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F145730%2Fmerge

The command will test the builders whose names match following regular expression: s390x RHEL9

The builders matched are:

  • s390x RHEL9 LTO PR
  • s390x RHEL9 PR
  • s390x RHEL9 Refleaks PR
  • s390x RHEL9 LTO + PGO PR

@hugovk hugovk merged commit 19676e5 into python:main Mar 10, 2026
59 checks passed
@miss-islington-app
Copy link

Thanks @emmatyping for the PR, and @hugovk for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

@hugovk
Copy link
Member

hugovk commented Mar 10, 2026

Thank you!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 10, 2026
pythonGH-145730)

(cherry picked from commit 19676e5fc28bdee8325a062a31ddeee60960cf75)

Co-authored-by: Emma Smith <emma@emmatyping.dev>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 10, 2026
pythonGH-145730)

(cherry picked from commit 19676e5fc28bdee8325a062a31ddeee60960cf75)

Co-authored-by: Emma Smith <emma@emmatyping.dev>
@bedevere-app
Copy link

bedevere-app bot commented Mar 10, 2026

GH-145733 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Mar 10, 2026
@bedevere-app
Copy link

bedevere-app bot commented Mar 10, 2026

GH-145734 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

X Tutup