fix(tests): make Athena S3 prefix tests self cleaning to avoid flaky CI reruns - #5987
Open
Chaitanya-0310 wants to merge 2 commits into
Open
fix(tests): make Athena S3 prefix tests self cleaning to avoid flaky CI reruns#5987Chaitanya-0310 wants to merge 2 commits into
Chaitanya-0310 wants to merge 2 commits into
Conversation
…CI reruns test_clear_partition_data and test_hive_truncate_table asserted their S3 test prefix started empty. That prefix is derived from the pytest session's testrun_uid plus the test's name, so it stays stable across pytest-rerunfailures retries within the same session. If a prior attempt got far enough to CTAS into that prefix before failing for an unrelated reason, the retry's very first assertion would fail deterministically since nothing ever cleared the objects left behind. Add an s3_delete_objects helper (mirroring the existing s3_list_objects helper) and call it before the emptiness assertion in both tests so they clean up after any previous attempt instead of assuming a clean slate. Fixes SQLMesh#5971 Signed-off-by: Chaitanya Panchal <chaitanyapp03@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5971
What's going on
test_clear_partition_dataandtest_hive_truncate_tableboth start with the same assumption that their S3 test prefix is empty before they do anything:That's what's actually failing in CI, not the partition-clearing logic itself (that part of the test never even runs once this assertion trips). Here's a real failure from the logs:
https://github.com/SQLMesh/sqlmesh/actions/runs/32524629055/job/96906313004
FAILED ...test_clear_partition_data[[query]athena] - AssertionError: assert 3 == 0
...4 rerun in 1147.41s...
Why it happens
Turns out the S3 prefix these tests write to isn't as "fresh" as the test assumes. It's built in conftest.py like this:
testrun_uid stays the same for the whole pytest session, and originalname is just the test's function name so a single test keeps hitting the exact same S3 prefix across every pytest rerunfailures retry in that run. If a first attempt gets as far as ctas() and then fails afterward for some unrelated, transient reason (Glue/Athena metadata lag, etc.), whatever it wrote to S3 just sits there. The retry hits that same prefix, and its very first assertion fails deterministically because nothing ever cleaned up after the failed attempt. That lines up exactly with what the log shows: 3 leftover files, all under src_table/, which is only ever written by the ctas() call earlier in the test.
Worth calling out: this isn't a bug in _clear_partition_data itself. That logic is checked further down in the test and never gets reached.
The fix
Added a small s3_delete_objects helper next to the existing s3_list_objects one, and call it right before the "prefix should be empty" assertion in both tests. So instead of just hoping the prefix is clean, the test makes sure it is. Should make both tests self-healing against this exact class of flake.
I left test_clear_partition_data_multiple_columns alone it doesn't have this "must start empty" assertion, it just compares before/after counts, so it isn't hit by this issue.
Checklist
make styleand fixed any issuesmake fast-test)git commit -s) per the DCO