mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Make sure locker allows reentrant lock acquisition
This commit is contained in:
25
test/unit/util/locking/PartialReadWriteLocker.test.ts
Normal file
25
test/unit/util/locking/PartialReadWriteLocker.test.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { PartialReadWriteLocker } from '../../../../src/util/locking/PartialReadWriteLocker';
|
||||
import type { ResourceLocker } from '../../../../src/util/locking/ResourceLocker';
|
||||
|
||||
describe('A PartialReadWriteLocker', (): void => {
|
||||
let resourceLocker: jest.Mocked<ResourceLocker>;
|
||||
const resourceId = { path: 'http://test.com/resource' };
|
||||
let locker: PartialReadWriteLocker;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
resourceLocker = {
|
||||
acquire: jest.fn(),
|
||||
release: jest.fn(),
|
||||
};
|
||||
|
||||
locker = new PartialReadWriteLocker(resourceLocker);
|
||||
});
|
||||
|
||||
it('can lock resources.', async(): Promise<void> => {
|
||||
await expect(locker.withReadLock(resourceId, (): number => 5)).resolves.toBe(5);
|
||||
expect(resourceLocker.acquire).toHaveBeenCalledTimes(1);
|
||||
expect(resourceLocker.acquire).toHaveBeenLastCalledWith(resourceId);
|
||||
expect(resourceLocker.release).toHaveBeenCalledTimes(1);
|
||||
expect(resourceLocker.release).toHaveBeenLastCalledWith(resourceId);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user