Skip to content

Test-ordering flakiness in tests/test_pg_integration.py::TestMaintenanceOps::test_clear_find_and_rebuild_* #163

@jensens

Description

@jensens

Symptoms

Three tests in `tests/test_pg_integration.py::TestMaintenanceOps` fail when run consecutively but pass in isolation:

  • `test_clear_find_and_rebuild_hierarchy`
  • `test_clear_find_and_rebuild_survives_missing_path_column`
  • `test_clear_find_and_rebuild_indexes_discussion_items`

Reproduce

Fails (6 tests of the class run in declaration order):
```
.venv/bin/pytest tests/test_pg_integration.py::TestMaintenanceOps -v

→ 3 failed, 3 passed

```

Passes (each in isolation):
```
.venv/bin/pytest tests/test_pg_integration.py::TestMaintenanceOps::test_clear_find_and_rebuild_hierarchy

→ 1 passed

```

Also fails when running the entire suite:
```
.venv/bin/pytest tests/ -q

→ 3 failed, 1481 passed, 39 skipped

```

Likely cause

State contamination between tests — an earlier test in `TestMaintenanceOps` leaves the Plone site in a state that one of the three `clear_find_and_rebuild` tests doesn't tolerate. Candidates:

  • ZODB transaction not rolled back cleanly
  • `object_state` rows from a prior test not cleared by the per-test setup
  • Connection pool state (request-scoped conn / probe cache / extraction queue) leaking across tests

Suggested investigation

  1. Run `pytest --lf` twice to confirm deterministic failure.
  2. Add `tearDown` asserts checking object_state row count after each test.
  3. Check whether `_clean_db()` / fixture teardown is symmetric with setup — likely fixture uses `pg_terminate_backend` then `DROP TABLE`, but the Plone site object in ZODB persists across test methods in the same class.
  4. Compare with `TestPGIntegration` fixtures that test similar maintenance ops — may already have the right isolation pattern.

Impact

Not a production bug — only affects test-suite completeness. Workaround: run the 3 tests individually. Does not block shipping; but needs fixing before we can rely on the full suite as a CI gate.

Context

Discovered during PR α test-suite verification (#162). All other tests (`test_suggestions.py`, etc.) are stable; this is localized to `TestMaintenanceOps`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions