Skip to content

Fix flaky test_hidden_tables under CPU load - #3082

Merged
simonw merged 1 commit into
mainfrom
claude/ecstatic-bell-52brii
Nov 17, 2026
Merged

simonw merged 1 commit into
mainfrom
claude/ecstatic-bell-52brii

Conversation

@simonw

@simonw simonw commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

test_hidden_tables fails intermittently under pytest -n auto and passes when run on its own.

Claude Fable 5.2 Medium

Cause

The test created its tables with db.execute() on an anonymous in-memory database (is_memory=True, no memory_name). Each thread in the executor pool opens its own :memory: connection, which is a separate empty database.

Run alone, every query lands on the same single pool thread, so the test passes. Under CPU contention the main thread can submit the next query before the worker has marked itself idle, so ThreadPoolExecutor starts a second thread. That thread gets a fresh empty database and hidden_table_names() returns []:

>       assert await db.hidden_table_names() == [
            "f_config",
            ...
E       AssertionError: assert [] == ['f_config', ...'r_node', ...]
tests/test_internals_database.py:1096: AssertionError

This is a timing race inside the test, not test ordering or state shared between tests.

Fix

The test now uses a named in-memory database (memory_name="test_hidden_tables"), which is shared between connections, and creates its tables with execute_write(). The assertions are unchanged.

Only the test changes. datasette/database.py is untouched, so anonymous in-memory databases still get one database per thread.

Verification

  • Reproduced the failure on unmodified main in the full suite with -n auto.
  • A standalone script running the old test body 300 times never failed on an idle machine. Under CPU load about a fifth of runs saw missing tables, and every one of those had used more than one pool thread.
  • With the fix, the full suite under -n auto passed three times in a row (3332 passed, 0 failed).

Generated by Claude Code

The test created tables with db.execute() on an anonymous in-memory
database. Each executor thread gets its own separate :memory: database,
so when the pool started a second thread the later queries saw an empty
database. Use a named in-memory database and execute_write() instead.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016BvfqD65qQzZhb7enTZ1B2
@simonw
simonw merged commit 97c4542 into main Nov 17, 2026
13 checks passed
@simonw
simonw deleted the claude/ecstatic-bell-52brii branch November 17, 2026 06:41
@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (ea03655) to head (c0a8c97).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #3082   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files         79      79           
  Lines      13978   13978           
=====================================
  Misses     13978   13978           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants