mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
31 lines
1.0 KiB
TypeScript
31 lines
1.0 KiB
TypeScript
import { WrappedExpiringResourceLocker } from '../../../src/storage/WrappedExpiringResourceLocker';
|
|
|
|
describe('A WrappedExpiringResourceLocker', (): void => {
|
|
it('emits an error event when releasing the lock errors.', async(): Promise<void> => {
|
|
jest.useFakeTimers();
|
|
|
|
// Create a locker that fails upon release
|
|
const faultyLocker = {
|
|
acquire(): any {
|
|
return {
|
|
async release(): Promise<never> {
|
|
throw new Error('Release error');
|
|
},
|
|
};
|
|
},
|
|
};
|
|
const expiringLocker = new WrappedExpiringResourceLocker(faultyLocker, 1000);
|
|
const expiringLock = await expiringLocker.acquire({} as any);
|
|
const errorCallback = jest.fn();
|
|
expiringLock.on('error', errorCallback);
|
|
|
|
// Let the lock expire
|
|
jest.advanceTimersByTime(1000);
|
|
await Promise.resolve();
|
|
|
|
// Verify the error has been emitted
|
|
expect(errorCallback).toHaveBeenCalledTimes(1);
|
|
expect(errorCallback).toHaveBeenLastCalledWith(new Error('Release error'));
|
|
});
|
|
});
|