Skip to content

Commit

Permalink
Reimplement global timeouts.request usage
Browse files Browse the repository at this point in the history
Updated and added test cases to control the behavior:
- if application env has no timeouts.request in the config Procedure fallback to 0 timeout
- config.server.timeouts.request applied to procedure script execution
- local timeout setting of the script overrides global timeouts.request  in both directions.

Closes: #1947
Refs: #1948
PR-URL: #1949
  • Loading branch information
KLarpen authored Dec 19, 2023
1 parent fa4d0bb commit cf552d5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased][unreleased]

- Fixed API endpoints local queue settings applying
- Reimplement global timeouts.request usage during a Procedure invocation

## [3.0.13][] - 2023-10-22

Expand Down
3 changes: 2 additions & 1 deletion lib/procedure.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class Procedure {
this.description = exp.description || '';
this.access = exp.access || '';
this.validate = exp.validate || null;
this.timeout = exp.timeout || 0;
const { timeouts } = application.config.server;
this.timeout = (exp.timeout ?? timeouts.request) || 0;
this.serializer = exp.serialize || null;
this.protocols = exp.protocols || null;
this.deprecated = exp.deprecated || false;
Expand Down
1 change: 1 addition & 0 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const application = {
absolute(relative) {
return path.join(this.path, relative);
},
config: { server: { timeouts: {} } },
};

metatests.testAsync('lib/api load', async (test) => {
Expand Down
34 changes: 34 additions & 0 deletions test/procedure.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ metatests.testAsync('lib/procedure', async (test) => {
async enter() {},
leave() {},
},
config: { server: { timeouts: {} } },
};

const procedure = new Procedure(script, 'method', application);
Expand Down Expand Up @@ -65,6 +66,7 @@ metatests.testAsync('lib/procedure validate', async (test) => {
async enter() {},
leave() {},
},
config: { server: { timeouts: {} } },
};
const procedure = new Procedure(script, 'method', application);

Expand Down Expand Up @@ -94,6 +96,7 @@ metatests.testAsync('lib/procedure validate async', async (test) => {
async enter() {},
leave() {},
},
config: { server: { timeouts: {} } },
};
const procedure = new Procedure(script, 'method', application);

Expand Down Expand Up @@ -123,6 +126,7 @@ metatests.testAsync('lib/procedure timeout', async (test) => {
async enter() {},
leave() {},
},
config: { server: { timeouts: { request: 20 } } },
};

const procedure = new Procedure(script, 'method', application);
Expand Down Expand Up @@ -157,6 +161,7 @@ metatests.testAsync('lib/procedure queue', async (test) => {
async enter() {},
leave() {},
},
config: { server: { timeouts: {} } },
};

const rpc = async (proc, args) => {
Expand Down Expand Up @@ -203,3 +208,32 @@ metatests.testAsync('lib/procedure queue', async (test) => {
return last.value;
}, new Error('Semaphore queue is full'));
});

metatests.testAsync('lib/procedure global timeouts.request', async (test) => {
const DONE = 'success';

const script = () => ({
timeout: undefined,

method: async ({ waitTime }) =>
new Promise((resolve) => {
setTimeout(() => resolve(DONE), waitTime);
}),
});

const application = {
Error,
semaphore: {
async enter() {},
leave() {},
},
config: { server: { timeouts: { request: 10 } } },
};

const procedure = new Procedure(script, 'method', application);

await test.rejects(
async () => procedure.invoke({}, { waitTime: 20 }),
new Error('Timeout of 10ms reached'),
);
});

0 comments on commit cf552d5

Please sign in to comment.