Lina 9a1f324685
feat: Create VoidLocker to disable locking resources
* 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>
2021-12-16 15:09:58 +01:00

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);
});
});