Skip to content

Cache-hit tests fail when concurrent test queries push their executions out of the cache_size window #816

Description

@laughingman7743

Use case

TestCursor::test_cache_size fails intermittently in CI. The third execute(query, cache_size=100) returns a new query ID instead of one of the two earlier ones:

AssertionError: assert 'ad46191a-…' in ['cbc9ad0e-…', '5b851bb1-…']
tests/pyathena/test_cursor.py:112

It failed twice in two days: in run 35939526000 on Python 3.12, and in run 36024670053 on Python 3.11. Both times, other pull requests' Test runs overlapped, and a rerun alone passed.

The cause is test isolation, not the cache feature.

  • cache_size=100 searches only the 100 most recent executions in the work group.
  • The test uses the default primary work group, which almost every other test also uses.
  • While a single Test run is active, primary receives 30–50 executions per second, so the test's own executions leave the window within a few seconds.
  • Overlapping runs raise that rate further.

The rerun added in #811 applies only to Athena service-side error messages, so it doesn't cover this AssertionError. Running the three suites in parallel (#814) increases the rate in primary.

The investigation details are in the first comment.

Proposed change

  • Run the tests that assert a cache hit in the pyathena work group (ENV.work_group). That work group received about 40 executions during a whole Test run.
    • test_cache_size_with_work_group already does this.
    • The same change applies to test_cache_size and the cache-hit part of test_cache_expiration_time_with_cache_size.
    • Tests that assert a cache miss, and the mocked schema/catalog tests, need no change.
  • In docs/usage.md, state that cache_size counts the most recent executions in the work group, including other clients' queries, so a busy work group can push a previous execution out of the window.

Alternatives considered:

  • Increasing cache_size in the tests (for example, to 1000) still depends on load. At the rates measured with overlapping runs, 1000 executions take only about 8–25 seconds. It also makes each lookup page through 20 ListQueryExecutions and BatchGetQueryExecution calls.
  • A dedicated work group for the cache tests isolates them fully. However, it needs a CloudFormation, IAM, and environment variable change, and the pyathena work group is already quiet enough.
  • Adding the failure to the rerun list would hide the load dependency without removing it.

Validation plan (if implementing)

  • Run the affected tests with uv run --env-file .env pytest -n 1 tests/pyathena/test_cursor.py -k cache.
  • Then run the full just test pyathena in CI.
  • Confirm the assertions still distinguish a hit from a miss.

This uses the existing test account's pyathena work group. No new AWS resources are needed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions