test(supabase): close the gaps two M3 mutations went through

A client whose only link was voided while current must not count the animal;
B linking its own animal to a client of A must not wait on A's lock. Also a
relation create racing the archive of its animal, and a replay changing the
initial relation's role.
This commit is contained in:
bchanot committed 2026-10-26 00:57:38 +01:00
1 parent b54c8e5bd8
commit 533a1c497d
2 files changed
+37 -3

No files matched your search

@@ -425,7 +425,11 @@ describe('animals and relations through PostgREST, per role', () => {
})
it('a caller outside the workspace never waits on its locks', async () => {
const bAnimal = idOf(
await createAnimal(b, await workspaceOf(b.id), { name: 'Lock probe' }),
)
const holder = sql(`begin;
select 1 from public.clients where id = '${marie}' for update;
select 1 from public.animals where id = '${eclair}' for update;
select 1 from public.animal_client_relations where id = '${relation}' for update;
select pg_sleep(2); commit;`)
@@ -439,13 +443,14 @@ describe('animals and relations through PostgREST, per role', () => {
b.token,
),
link(b, eclair, marie, 'contact'),
link(b, bAnimal, marie, 'contact'),
])
const elapsed = Date.now() - started
await holder
expect(results.map(shape)).toEqual([NOT_FOUND, NOT_FOUND, NOT_FOUND])
expect(results.map(shape)).toEqual(Array(4).fill(NOT_FOUND))
expect(elapsed).toBeLessThan(1000)
console.log(
`[measure] A's animal and relation locked 2 s: B's three refusals answered in ${elapsed} ms`,
`[measure] A's client, animal and relation locked 2 s: B's four refusals answered in ${elapsed} ms`,
)
})
@@ -621,6 +626,29 @@ describe('concurrent writes', () => {
)
})
it('a relation create racing the archive of its animal: created before, or refused archived after', async () => {
for (let round = 0; round < 10; round++) {
const animal = idOf(
await createAnimal(a, wA, { name: `Animal archive race ${round}` }),
)
const [linked, archived] = await Promise.all([
link(a, animal, clients[3], 'keeper'),
rpc(
'set_animal_archived',
{ animal_id: animal, archived: true },
a.token,
),
])
expect(messageOf(archived)).toBe('ok')
expect(['ok', 'archived']).toContain(messageOf(linked))
expect(
await sql(
`select count(*) from public.animal_client_relations where animal_id = '${animal}'`,
),
).toBe(messageOf(linked) === 'ok' ? '1' : '0')
}
})
it('the budget is one counter for clients, animals and relations: at 990, 30 mixed writes, exactly 10 pass', async () => {
const animals: string[] = []
for (let i = 0; i < 10; i++)