Every PromptManagerAPI sweeps its database's folder at startup for the stages, uploads and safety-backup copies an interrupted restore left. The API test fixtures created their database directly in the system temp folder, so any other test process starting an API there (another worktree's suite, a pre-push hook, an agent's targeted run) deleted this process's in-flight restore files. The restore, epoch and retirement tests then failed with 'staged restore changed', 'unable to open database file' or 503 instead of 409. Busy machines fail because they are running other suites, not because they are slow: the same CPU load with a private TMPDIR passes. private_temp_db() puts the fixture database in a new folder removed at cleanup (with any safety backups a restore left beside it). A regression test sweeps a stand-in shared folder in the middle of a multipart restore, as another suite's startup would.
25 lines
1.0 KiB
Python
25 lines
1.0 KiB
Python
"""A temp SQLite database in a folder no other test process shares (#346).
|
|
|
|
``PromptManagerAPI`` sweeps its database's folder at startup for the stages,
|
|
uploads and safety-backup copies an interrupted restore or backup left. A
|
|
fixture database directly in the system temp folder made every other test
|
|
process that started an API (another worktree's suite, a pre-push hook) delete
|
|
this process's in-flight restore files, and left safety backups behind there.
|
|
"""
|
|
|
|
import tempfile
|
|
|
|
|
|
def private_temp_db(case):
|
|
"""Return a closed ``NamedTemporaryFile`` handle for an empty ``.db`` file.
|
|
|
|
The file lives in a new folder that ``case`` removes at cleanup, after its
|
|
own teardown has closed and unlinked the database (cleanups run after
|
|
``tearDown``), together with anything a restore or backup left next to it.
|
|
"""
|
|
folder = tempfile.TemporaryDirectory(ignore_cleanup_errors=True)
|
|
case.addCleanup(folder.cleanup)
|
|
handle = tempfile.NamedTemporaryFile(delete=False, suffix=".db", dir=folder.name)
|
|
handle.close()
|
|
return handle
|