Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(drain-lease): share-lock tests take over with a DELETE, which conflicts with any fence lock strength
garrytandee334040e99
diff --git a/test/drain-lease-stamp-fence.test.ts b/test/drain-lease-stamp-fence.test.tsindex abea0c1332..2aa95104bc 100644--- a/test/drain-lease-stamp-fence.test.ts+++ b/test/drain-lease-stamp-fence.test.ts@@ -82,10 +82,13 @@ for (const backend of testBackends()) {// Postgres only: PGLite is one connection, so nothing can try a takeover while the stamp's transaction is open.if (backend === 'postgres') {- /** A takeover as tryAcquireDbLock's upsert or --break-lock writes it, from another connection, giving up after 1 s. */+ /**+ * A takeover as --break-lock writes it (a DELETE, which conflicts with every row lock a fence can take, FOR KEY SHARE+ * included), from another connection, giving up after 1 s.+ */const takeoverDuring = (engine: BrainEngine) => engine.transaction(async tx => {await tx.executeRaw("SET LOCAL lock_timeout = '1s'");- return (await tx.executeRaw('UPDATE gbrain_cycle_locks SET acquisition_token=gen_random_uuid() WHERE id=$1 RETURNING id', [syncLockId('default')])).length;+ return (await tx.executeRaw('DELETE FROM gbrain_cycle_locks WHERE id=$1 RETURNING id', [syncLockId('default')])).length;}).catch((error: { code?: string }) => error.code ?? String(error));test('a folded stamp holds the lease row FOR SHARE until its import commits, so a takeover waits', () => brain(async ({ engine, root }) => {diff --git a/test/e2e/drain-lease-fence-postgres.test.ts b/test/e2e/drain-lease-fence-postgres.test.tsindex 77635ecbc9..35a2e624fb 100644--- a/test/e2e/drain-lease-fence-postgres.test.ts+++ b/test/e2e/drain-lease-fence-postgres.test.ts@@ -25,10 +25,11 @@ afterAll(async () => { await close?.(); });run('the fence holds the lease row FOR SHARE, so it blocks a takeover until its transaction ends', async () => {const other = postgres(url, { max: 1, prepare: false });- // A takeover as tryAcquireDbLock's upsert or --break-lock writes it, from another connection, giving up after 1 s.+ // A takeover as --break-lock writes it (a DELETE, which conflicts with every row lock a fence can take, FOR KEY SHARE+ // included), from another connection, giving up after 1 s.const takeover = () => other.begin(async tx => {await tx.unsafe("SET LOCAL lock_timeout = '1s'");- return tx.unsafe('UPDATE gbrain_cycle_locks SET acquisition_token = gen_random_uuid() WHERE id = $1 RETURNING id', [syncLockId('default')]);+ return tx.unsafe('DELETE FROM gbrain_cycle_locks WHERE id = $1 RETURNING id', [syncLockId('default')]);});try {let duringFence: unknown;