فهرست منبع

Give the engine and restore tests their own temp folder so they stop clashing (#494)

Both files run a real backup of the same test workshop, staged at the engine's fixed
path under os.tmpdir(), and Vitest runs them at the same time. A run in one file could
delete the data file the other was about to read, failing CI now and then with
"ENOENT ... torqvoice-backup-staging/org1/data.json". Each file now points TMPDIR at
the temp folder it already makes and removes, and puts the old value back when done.
Bernt Christian Egeland 2 روز پیش
والد
کامیت
0097eea32e
2فایلهای تغییر یافته به همراه18 افزوده شده و 0 حذف شده
  1. 9 0
      src/__tests__/lib/backup/engine.test.ts
  2. 9 0
      src/__tests__/lib/backup/restore.test.ts

+ 9 - 0
src/__tests__/lib/backup/engine.test.ts

@@ -243,6 +243,13 @@ const dataDir = path.join(root, 'data')
 const repoDir = path.join(root, 'repo')
 const uploadsDir = path.join(dataDir, 'uploads', ORG)
 const fake = path.join(root, 'restic.sh')
+// The engine stages each workshop's data file at a fixed path under
+// os.tmpdir() and deletes it after the run. restore.test.ts stages the same
+// workshop, and Vitest runs the two files at the same time, so each points
+// os.tmpdir() at its own folder; with a shared one, a run in one file deletes
+// the data file the other is about to read.
+const outerTmpdir = process.env.TMPDIR
+process.env.TMPDIR = root
 const savedEnv = { ...process.env }
 
 function heredoc(line: string): string {
@@ -450,6 +457,8 @@ afterEach(() => {
 })
 
 afterAll(() => {
+  if (outerTmpdir === undefined) delete process.env.TMPDIR
+  else process.env.TMPDIR = outerTmpdir
   rmSync(root, { recursive: true, force: true })
 })
 

+ 9 - 0
src/__tests__/lib/backup/restore.test.ts

@@ -270,6 +270,13 @@ const SAFETY_FAILED = 'Could not take a safety copy of the workshop first; nothi
 
 const root = mkdtempSync(path.join(tmpdir(), 'backup-restore-test-'))
 const dataDir = path.join(root, 'data')
+// The engine stages each workshop's data file at a fixed path under
+// os.tmpdir() and deletes it after the run. engine.test.ts stages the same
+// workshop, and Vitest runs the two files at the same time, so each points
+// os.tmpdir() at its own folder; with a shared one, a run in one file deletes
+// the data file the other is about to read.
+const outerTmpdir = process.env.TMPDIR
+process.env.TMPDIR = root
 const savedEnv = { ...process.env }
 
 /** A snapshot of the staged data file and the uploads folder, as the engine takes them. */
@@ -346,6 +353,8 @@ afterEach(() => {
 })
 
 afterAll(() => {
+  if (outerTmpdir === undefined) delete process.env.TMPDIR
+  else process.env.TMPDIR = outerTmpdir
   rmSync(root, { recursive: true, force: true })
 })