diff --git a/apps/server/src/infra/preview-generator/preview.producer.spec.ts b/apps/server/src/infra/preview-generator/preview.producer.spec.ts index 47adea158a6..e6c5b680aff 100644 --- a/apps/server/src/infra/preview-generator/preview.producer.spec.ts +++ b/apps/server/src/infra/preview-generator/preview.producer.spec.ts @@ -12,9 +12,10 @@ import { PreviewProducer } from './preview.producer'; describe('PreviewProducer', () => { let module: TestingModule; let service: PreviewProducer; - let configService: DeepMocked; let amqpConnection: DeepMocked; + const timeout = 10000; + beforeAll(async () => { await setupEntities(); module = await Test.createTestingModule({ @@ -30,14 +31,20 @@ describe('PreviewProducer', () => { }, { provide: ConfigService, - useValue: createMock(), + useValue: createMock({ + get: jest.fn().mockImplementation((key: string) => { + if (key === 'INCOMING_REQUEST_TIMEOUT') { + return timeout; + } + throw new Error('Config key not found'); + }), + }), }, ], }).compile(); service = module.get(PreviewProducer); amqpConnection = module.get(AmqpConnection); - configService = module.get(ConfigService); }); afterAll(async () => { @@ -47,6 +54,7 @@ describe('PreviewProducer', () => { afterEach(() => { jest.resetAllMocks(); }); + it('should be defined', () => { expect(service).toBeDefined(); }); @@ -54,8 +62,6 @@ describe('PreviewProducer', () => { describe('generate', () => { describe('when valid params are passed and amqp connection return with a message', () => { const setup = () => { - const timeout = 10000; - const params: PreviewFileOptions = { originFilePath: 'file/test.jpeg', previewFilePath: 'preview/text.webp', @@ -67,13 +73,13 @@ describe('PreviewProducer', () => { const message = []; amqpConnection.request.mockResolvedValueOnce({ message }); - configService.get.mockReturnValue(timeout); const expectedParams = { exchange: FilesPreviewExchange, routingKey: FilesPreviewEvents.GENERATE_PREVIEW, payload: params, timeout, + expiration: timeout * 1.5, }; return { params, expectedParams, message }; diff --git a/apps/server/src/infra/rabbitmq/rpc-message-producer.spec.ts b/apps/server/src/infra/rabbitmq/rpc-message-producer.spec.ts index b2e94ea676b..fc0e2629485 100644 --- a/apps/server/src/infra/rabbitmq/rpc-message-producer.spec.ts +++ b/apps/server/src/infra/rabbitmq/rpc-message-producer.spec.ts @@ -59,6 +59,7 @@ describe('RpcMessageProducer', () => { routingKey: TestEvent, payload: params, timeout, + expiration: timeout * 1.5, }; return { params, expectedParams, message }; diff --git a/apps/server/src/infra/rabbitmq/rpc-message-producer.ts b/apps/server/src/infra/rabbitmq/rpc-message-producer.ts index 8a239b2cbcd..84b74f6e173 100644 --- a/apps/server/src/infra/rabbitmq/rpc-message-producer.ts +++ b/apps/server/src/infra/rabbitmq/rpc-message-producer.ts @@ -27,11 +27,15 @@ export abstract class RpcMessageProducer { } protected createRequest(event: string, payload: unknown) { + // expiration should be greater than timeout + const expiration = this.timeout > 0 ? this.timeout * 1.5 : undefined; + return { exchange: this.exchange, routingKey: event, payload, timeout: this.timeout, + expiration, }; } } diff --git a/apps/server/src/modules/files-storage-client/service/files-storage.producer.spec.ts b/apps/server/src/modules/files-storage-client/service/files-storage.producer.spec.ts index 12b476fb84c..517b0be1593 100644 --- a/apps/server/src/modules/files-storage-client/service/files-storage.producer.spec.ts +++ b/apps/server/src/modules/files-storage-client/service/files-storage.producer.spec.ts @@ -12,7 +12,6 @@ import { FilesStorageProducer } from './files-storage.producer'; describe('FilesStorageProducer', () => { let module: TestingModule; let service: FilesStorageProducer; - let configService: DeepMocked; let amqpConnection: DeepMocked; const timeout = 10000; @@ -32,21 +31,30 @@ describe('FilesStorageProducer', () => { }, { provide: ConfigService, - useValue: createMock(), + useValue: createMock({ + get: jest.fn().mockImplementation((key: string) => { + if (key === 'INCOMING_REQUEST_TIMEOUT_COPY_API') { + return timeout; + } + throw new Error('Config key not found'); + }), + }), }, ], }).compile(); service = module.get(FilesStorageProducer); amqpConnection = module.get(AmqpConnection); - configService = module.get(ConfigService); - configService.get.mockReturnValue(timeout); }); afterAll(async () => { await module.close(); }); + afterEach(() => { + jest.clearAllMocks(); + }); + describe('copyFilesOfParent', () => { describe('when amqpConnection return with error in response', () => { const setup = () => { @@ -111,6 +119,7 @@ describe('FilesStorageProducer', () => { routingKey: FilesStorageEvents.COPY_FILES_OF_PARENT, payload: params, timeout, + expiration: timeout * 1.5, }; return { params, expectedParams, message }; @@ -163,6 +172,7 @@ describe('FilesStorageProducer', () => { routingKey: FilesStorageEvents.LIST_FILES_OF_PARENT, payload: parentId, timeout, + expiration: timeout * 1.5, }; const message = []; @@ -221,6 +231,7 @@ describe('FilesStorageProducer', () => { routingKey: FilesStorageEvents.DELETE_FILES_OF_PARENT, payload: parentId, timeout, + expiration: timeout * 1.5, }; return { parentId, message, expectedParams }; @@ -275,6 +286,7 @@ describe('FilesStorageProducer', () => { routingKey: FilesStorageEvents.DELETE_FILES, payload: [recordId], timeout, + expiration: timeout * 1.5, }; return { recordId, message, expectedParams }; }; @@ -329,6 +341,7 @@ describe('FilesStorageProducer', () => { routingKey: FilesStorageEvents.REMOVE_CREATORID_OF_FILES, payload: creatorId, timeout, + expiration: timeout * 1.5, }; return { creatorId, message, expectedParams };