Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/LogicService/service.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion src/Root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions src/__tests__/Root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down