CommunitySolidServer/test/unit/util/LockUtil.test.ts
Thomas Dupont fa78bc6856 feat: add a process-/thread-safe file-based ResourceLocker
test: unit test succeeds

fix: not quiting loop when releasing unexisting lock

refactor: pull wait() function into TimerUtils

feat: store all locks inside a single lock folder

feat: use md5 hashing for filepath hashes

test: coverage back to 100%

fix: store locks in proper .internal/locks folder
feat: reworked tryfn

test: coverage back to 100%

buidl: package json types next to lib

style: linting

dos: add more documentation to Locker classes

refactor: SingleThreadedResourceLocker -> MemoryResourceLocker

refactor: MultiThreadedResourceLocker -> FileSystemResourceLocker

feat: update all file-based backend configs to use the new FileSystemResourceLocker

feat: add warning on starting the MemoryResourceLocker in a worker process

test: coverage back to 100%

fix: finalizer of file.json was configured wrong

docs: updated release notes for 5.0.0

refactor: incorporated changes so far

refactor: retryFunctions are less complex now

test: jitter fix
2022-04-28 14:12:30 +02:00

32 lines
995 B
TypeScript

import { setJitterTimeout } from '../../../src/util/LockUtils';
jest.useFakeTimers();
describe('LockUtil', (): void => {
describe('#setJitterTimout', (): void => {
it('works without jitter.', async(): Promise<void> => {
let result = '';
const promise = setJitterTimeout(1000).then((): void => {
result += 'ok';
});
expect(result).toHaveLength(0);
jest.advanceTimersByTime(1000);
await expect(promise).resolves.toBeUndefined();
expect(result).toBe('ok');
});
it('works with jitter.', async(): Promise<void> => {
jest.spyOn(global.Math, 'random').mockReturnValue(1);
let elapsed = Date.now();
const promise = setJitterTimeout(1000, 100).then((): void => {
elapsed = Date.now() - elapsed;
});
jest.runAllTimers();
await expect(promise).resolves.toBeUndefined();
expect(elapsed).toBe(1100);
// Clean up
jest.spyOn(global.Math, 'random').mockRestore();
});
});
});