diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f8332db..613c9868 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/procedure.js b/lib/procedure.js index 1c3caf7a..dbc4436e 100644 --- a/lib/procedure.js +++ b/lib/procedure.js @@ -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; diff --git a/test/api.js b/test/api.js index b7b8c640..762d16e0 100644 --- a/test/api.js +++ b/test/api.js @@ -14,6 +14,7 @@ const application = { absolute(relative) { return path.join(this.path, relative); }, + config: { server: { timeouts: {} } }, }; metatests.testAsync('lib/api load', async (test) => { diff --git a/test/procedure.js b/test/procedure.js index 89776d43..7bf34ada 100644 --- a/test/procedure.js +++ b/test/procedure.js @@ -15,6 +15,7 @@ metatests.testAsync('lib/procedure', async (test) => { async enter() {}, leave() {}, }, + config: { server: { timeouts: {} } }, }; const procedure = new Procedure(script, 'method', application); @@ -65,6 +66,7 @@ metatests.testAsync('lib/procedure validate', async (test) => { async enter() {}, leave() {}, }, + config: { server: { timeouts: {} } }, }; const procedure = new Procedure(script, 'method', application); @@ -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); @@ -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); @@ -157,6 +161,7 @@ metatests.testAsync('lib/procedure queue', async (test) => { async enter() {}, leave() {}, }, + config: { server: { timeouts: {} } }, }; const rpc = async (proc, args) => { @@ -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'), + ); +});