Correct the lock path.

This commit is contained in:
Sam Rose 2024-04-03 12:11:28 +01:00
parent dda0d1fb5b
commit b25912bc5e
No known key found for this signature in database
1 changed files with 4 additions and 2 deletions

View File

@ -1,13 +1,15 @@
import { GenericContainer, Wait } from "testcontainers"
import path from "path"
import lockfile from "proper-lockfile"
export default async function setup() {
const lockPath = path.resolve(__dirname, "globalSetup.ts")
if (process.env.REUSE_CONTAINERS) {
// If you run multiple tests at the same time, it's possible for the CouchDB
// shared container to get started multiple times despite having an
// identical reuse hash. To avoid that, we do a filesystem-based lock so
// that only one globalSetup.ts is running at a time.
lockfile.lockSync("globalSetup.lock")
lockfile.lockSync(lockPath)
}
try {
@ -45,7 +47,7 @@ export default async function setup() {
await couchdb.start()
} finally {
if (process.env.REUSE_CONTAINERS) {
lockfile.unlockSync("globalSetup.lock")
lockfile.unlockSync(lockPath)
}
}
}