Make test_migration_0061 query plan assertion deterministic

Open
#61 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
postgresql, python
Domain
databases, testing

Research direction

Start with server/tests/test_migration_0061.py, especially test_max_assigned_at_of_the_yield_uses_the_index and its EXPLAIN assertion. Read how the test sets planner options and creates its database state, then choose an approach that makes the result independent of close planner costs. Done means the assertion is deterministic and the test passes 20 consecutive runs against a clean database, with no schema, migration, or application changes.

Written by the indexing model from the issue text.

Description

bug P3 server

Problem

test_max_assigned_at_of_the_yield_uses_the_index is flaky (server/tests/test_migration_0061.py:81). It asserts that the plan of the per-worker max(assigned_at) query contains Index Only Scan Backward using te_worker_assigned_idx (server/tests/test_migration_0061.py:116). It failed once in CI and passed when the same job was re-run on the same commit. In the failing run the planner chose Index Scan using task_executions_attempt_uk under an Aggregate.

The test turns off sequential and bitmap scans only (server/tests/test_migration_0061.py:103, server/tests/test_migration_0061.py:104). It runs on a table with no rows and no fresh statistics. The likely cause is that two index paths then cost about the same and the planner can pick either.

Proposed change

Make the test independent of the planner's choice. Options:

  • Insert enough rows for the worker and for other workers, run ANALYZE task_executions, then EXPLAIN.
  • Or keep the plan check but also fix the planner settings for the test so that only the intended index is a candidate.
  • Or assert the property that matters, that the index exists with (worker_id, assigned_at) columns in order and that the query returns the right value, and drop the plan text check.

Acceptance criteria

  • The test no longer depends on which index the planner picks when costs are close.
  • The test passes 20 consecutive runs against a clean database.
  • No schema, migration or application code changes.
Dominant language
Python
Stars
0
Forks
0
Avg merge
1d 1h
Merged PRs (30d)
10

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AInvirion/orcaster

All issues in AInvirion/orcaster

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.