blob: 13ac8984461df057bc9afebcc9e72401ffc02d3b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
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();
});
});
});
|