Skip to content

Commit

Permalink
fix: memory lock owner not updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed Sep 20, 2024
1 parent d5ca7c1 commit 5029dd0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/verrou/src/drivers/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class MemoryStore implements LockStore {
if (mutex.owner !== owner) throw new E_LOCK_NOT_OWNED()

mutex.releaser()
this.#locks.delete(key)
}

/**
Expand Down
22 changes: 22 additions & 0 deletions packages/verrou/src/test_suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,28 @@ export function registerStoreTestSuite(options: {
assert.deepEqual(result, '42')
})

test('run is exclusive with two factories', async ({ assert }) => {
const provider = new LockFactory(options.createStore())
const lock1 = provider.createLock('foo')
const lock2 = provider.createLock('foo')

let flag = false
lock1.run(async () => {
await sleep(500)
flag = true
})

assert.isFalse(flag)

const [, result] = await lock2.run(async () => {
assert.isTrue(flag)
return '42'
})

assert.isTrue(flag)
assert.deepEqual(result, '42')
})

test('exceptions during run do not leave mutex in locked state', async ({ assert }) => {
const provider = new LockFactory(options.createStore())
const lock = provider.createLock('foo')
Expand Down

0 comments on commit 5029dd0

Please sign in to comment.