diff --git a/examples/LogicService/service.schema.json b/examples/LogicService/service.schema.json index d2a7b45..0f2cc6e 100644 --- a/examples/LogicService/service.schema.json +++ b/examples/LogicService/service.schema.json @@ -7,6 +7,7 @@ "description": "Weird sum logic. Gets two numbers and adds them. The result is a length Fibonacci sequence. Add the sequence and get the result", "options": { "cache": 5, + "timeout": 3000, "runTimeValidation": { "request": true } diff --git a/src/Root.ts b/src/Root.ts index 6f4f27f..a2c5fd3 100644 --- a/src/Root.ts +++ b/src/Root.ts @@ -49,7 +49,11 @@ export class Root { try { if (!expired) { const timeout = ownTimeout || this.castToNumber(this.getSettingFromEnv('DEFAULT_REPONSE_TIMEOUT')); - return Date.now() + timeout * 1000; + return Date.now() + timeout; + } + if (ownTimeout) { + const customExpired = Date.now() + ownTimeout; + return Math.min(customExpired, expired); } return expired; } catch (error) { diff --git a/src/__tests__/Root.ts b/src/__tests__/Root.ts index ff5434c..88290f3 100644 --- a/src/__tests__/Root.ts +++ b/src/__tests__/Root.ts @@ -89,7 +89,7 @@ describe('Testing Root class methods', () => { jest.setSystemTime(0); const ENV = process.env; - const DEFAULT_REPONSE_TIMEOUT = 20; + const DEFAULT_REPONSE_TIMEOUT = 20_000; beforeAll(() => { jest.resetModules(); @@ -103,18 +103,18 @@ describe('Testing Root class methods', () => { test('Timeout timestamp is correctly generated. The timeout in seconds is taken from the environment variable', () => { const result = root.getExpiredProxy(); - expect(result).toBe(DEFAULT_REPONSE_TIMEOUT * 1000); + expect(result).toBe(DEFAULT_REPONSE_TIMEOUT); }); test('Timeout timestamp is correctly generated. The timeout in seconds is taken from the passed value', () => { - const customTimeout = 30; + const customTimeout = 30_000; const result = root.getExpiredProxy(undefined, customTimeout); - expect(result).toBe(customTimeout * 1000); + expect(result).toBe(customTimeout); }); test('Timeout timestamp is correctly generated. If the timeout is already set, it remains unchanged', () => { - const timeout = 40000; + const timeout = 40_000; const result = root.getExpiredProxy(timeout); expect(result).toBe(timeout);