mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00

* add: Add VoidLocker and unittest * Update src/util/locking/VoidLocker.ts Co-authored-by: Ruben Verborgh <ruben@verborgh.org> * Update src/util/locking/VoidLocker.ts Co-authored-by: Joachim Van Herwegen <joachimvh@gmail.com> * update: noop function and add debug void config * add: debug-void in readme * Update RELEASE_NOTES.md Co-authored-by: Joachim Van Herwegen <joachimvh@gmail.com> * Update config/util/README.md Co-authored-by: Joachim Van Herwegen <joachimvh@gmail.com> * add: missing line Co-authored-by: lina <lina7906@gmail.com> Co-authored-by: Ruben Verborgh <ruben@verborgh.org> Co-authored-by: Joachim Van Herwegen <joachimvh@gmail.com>
28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
import type { ResourceIdentifier } from '../../../../src';
|
|
import { VoidLocker } from '../../../../src/util/locking/VoidLocker';
|
|
|
|
describe('A VoidLocker', (): void => {
|
|
it('invokes the whileLocked function immediately with readLock.', async(): Promise<void> => {
|
|
const locker = new VoidLocker();
|
|
const identifier: ResourceIdentifier = { path: 'http://test.com/res' };
|
|
const whileLocked = jest.fn().mockImplementation((maintainLockFn: () => void): void => {
|
|
maintainLockFn();
|
|
});
|
|
|
|
await locker.withReadLock(identifier, whileLocked);
|
|
|
|
expect(whileLocked).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('invokes the whileLocked function immediately with writeLock.', async(): Promise<void> => {
|
|
const locker = new VoidLocker();
|
|
const identifier: ResourceIdentifier = { path: 'http://test.com/res' };
|
|
const whileLocked = jest.fn().mockImplementation((maintainLockFn: () => void): void => {
|
|
maintainLockFn();
|
|
});
|
|
await locker.withWriteLock(identifier, whileLocked);
|
|
|
|
expect(whileLocked).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|