* test(browser): seed resets on a scratch copy and publish them in one commit (#384) The concept and plain resets made hundreds of committed transactions on the live database; on a slow CI disk they queued behind WAL checkpoint syncs and took 30+ s. Each reset now copies the live database into a scratch database (backup API, no syncs), runs the unchanged seeder against it through an API proxy, and replaces the rows of the tables the seed changed in one live transaction. A commit by another live connection meanwhile fails the reset. tests/browser/reset_equivalence.py proves every reset kind leaves the same rows, files and response as the old path (PM_TEST_SEED_ON_LIVE=1). * test(browser): empty media folders by a rename, delete them in the background (#384) With the database commits gone, throttled resets still stalled in rmtree: unlinking the last fixture's files waits for their pending writeback. Each reseed now moves the old output and input folders into <root>/reset-trash and makes empty ones; a background thread deletes the trash, and the server's cleanup stops it and removes the rest before the temp root goes. * fix(test): recheck the live data version under the publish's write lock (#384) A writer whose transaction was open while the seed ran committed before BEGIN IMMEDIATE returned and its rows were overwritten. The publish now rechecks data_version under the lock, and restores foreign_keys and detaches the scratch database on every error path. * test(browser): keep the reset scratch database in /dev/shm when there is one (#384) Throttled runs still waited on the runner's disk while creating and rewriting the scratch database, whose pages were under writeback. * test(browser): keep the scratch on disk when /dev/shm is short, delete in place after cleanup (#384) The largest scratch copy is about 8 MB; Docker's default /dev/shm is 64 MB and shared with the browsers. A reset that empties a folder after the server's cleanup closed its trash deletes in place instead of starting a thread nobody stops. * fix(test): drop the gallery caches only after the reset's rows are published (#384) The seeders drop the Images listing at their end. Run on the scratch copy, that drop came before the publish, so a background walk in between could cache per-file values built from the live database's old rows: CI's inspector tag chip found 0 of 0 images. The proxy now records the drop and the seeder makes it after the publish, as the old reset did. * fix(test): remove /dev/shm reset scratch left by killed browser servers (#384) A server killed outright never runs its cleanup, and tmpfs keeps the scratch folder in memory until reboot: the Python suite's server tests left one per killed server. Scratch folders now carry the owner's pid, and each new one first removes those whose process is gone (POSIX only).
68 lines
2.5 KiB
Python
68 lines
2.5 KiB
Python
"""Browser-test media folders are emptied by a rename, deleted later (#384)."""
|
|
|
|
import tempfile
|
|
import threading
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from tests.browser.folder_trash import TRASH_NAME, close_trash, replace_folder
|
|
|
|
|
|
class TestFolderTrash(unittest.TestCase):
|
|
def setUp(self):
|
|
self.tmp = tempfile.TemporaryDirectory()
|
|
self.addCleanup(self.tmp.cleanup)
|
|
self.root = Path(self.tmp.name)
|
|
self.addCleanup(close_trash, self.root)
|
|
|
|
def trash_threads(self):
|
|
return [t for t in threading.enumerate() if t.name == "pm-reset-trash"]
|
|
|
|
def test_replaces_the_folder_with_an_empty_one(self):
|
|
folder = self.root / "output"
|
|
(folder / "nested").mkdir(parents=True)
|
|
(folder / "nested" / "image.png").write_bytes(b"png")
|
|
replace_folder(folder)
|
|
self.assertTrue(folder.is_dir())
|
|
self.assertEqual(list(folder.iterdir()), [])
|
|
close_trash(self.root)
|
|
self.assertFalse((self.root / TRASH_NAME).exists())
|
|
self.assertEqual(self.trash_threads(), [])
|
|
|
|
def test_a_missing_folder_is_created_without_a_trash(self):
|
|
replace_folder(self.root / "input")
|
|
self.assertTrue((self.root / "input").is_dir())
|
|
self.assertFalse((self.root / TRASH_NAME).exists())
|
|
self.assertEqual(self.trash_threads(), [])
|
|
|
|
def test_repeated_replacements_share_one_thread_and_all_are_removed(self):
|
|
folder = self.root / "output"
|
|
for number in range(5):
|
|
folder.mkdir(exist_ok=True)
|
|
(folder / f"{number}.png").write_bytes(b"png")
|
|
replace_folder(folder)
|
|
self.assertEqual(len(self.trash_threads()), 1)
|
|
close_trash(self.root)
|
|
self.assertEqual(list(folder.iterdir()), [])
|
|
self.assertFalse((self.root / TRASH_NAME).exists())
|
|
close_trash(self.root) # idempotent
|
|
|
|
|
|
class TestFolderTrashAfterClose(unittest.TestCase):
|
|
def test_a_replacement_after_close_deletes_in_place_without_a_thread(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
close_trash(root)
|
|
folder = root / "output"
|
|
folder.mkdir()
|
|
(folder / "late.png").write_bytes(b"png")
|
|
replace_folder(folder)
|
|
self.assertEqual(list(folder.iterdir()), [])
|
|
self.assertFalse((root / TRASH_NAME).exists())
|
|
names = [t.name for t in threading.enumerate()]
|
|
self.assertNotIn("pm-reset-trash", names)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|