0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 05:28:35 +00:00
renovatebot_renovate/lib/util/mutex.spec.ts
Sebastian Poxhofer f042ae4c9a
feat(cache): add a mutex utility and prevent parallel processing with the same cache key (#30815)
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2024-08-16 17:14:48 +00:00

29 lines
781 B
TypeScript

import { afterEach } from '@jest/globals';
import { acquireLock, getMutex } from './mutex';
describe('util/mutex', () => {
describe('getMutex', () => {
it('returns mutex with default namespace', () => {
expect(getMutex('test')).toBeDefined();
});
});
describe('acquireLock', () => {
afterEach(() => {
getMutex('test').release();
});
it('return lock function with default namespace', async () => {
await expect(acquireLock('test')).resolves.toBeFunction();
});
it('should lock if already used', async () => {
const mutex = getMutex('test');
const releaseLock = await acquireLock('test');
expect(mutex.isLocked()).toBeTrue();
releaseLock();
expect(mutex.isLocked()).toBeFalse();
});
});
});