From 9489953a8fa1e24bfc5b39886ac8189a035159fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20L=C3=B8vdal?= Date: Sat, 23 Sep 2023 22:04:48 +0200 Subject: [PATCH 1/4] Introduce timeout constant --- test/nodes/core/function/10-function_spec.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/nodes/core/function/10-function_spec.js b/test/nodes/core/function/10-function_spec.js index acb693208..d5d35d77e 100644 --- a/test/nodes/core/function/10-function_spec.js +++ b/test/nodes/core/function/10-function_spec.js @@ -1718,9 +1718,10 @@ describe('function node', function() { describe("init function", function() { it('should delay handling messages until init completes', function(done) { + const timeout_ms = 200; var flow = [{id:"n1",type:"function",wires:[["n2"]],initialize: ` return new Promise((resolve,reject) => { - setTimeout(resolve,200) + setTimeout(resolve, ${timeout_ms}); })`, func:"return msg;" }, @@ -1733,9 +1734,9 @@ describe('function node', function() { msg.delta = Date.now() - msg.payload; receivedMsgs.push(msg) if (receivedMsgs.length === 5) { - var errors = receivedMsgs.filter(msg => msg.delta < 200) + var errors = receivedMsgs.filter(msg => msg.delta < timeout_ms) if (errors.length > 0) { - done(new Error(`Message received before init completed - was ${msg.delta} expected >300`)) + done(new Error(`Message received before init completed - was ${msg.delta} expected >${timeout_ms}`)) } else { done(); } From 0c2ab13c485a4349d95106f880f21c3d4f524f37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20L=C3=B8vdal?= Date: Sat, 23 Sep 2023 22:05:37 +0200 Subject: [PATCH 2/4] Print all delta values in case of error, not just the last value Which might not even be the one triggering the error condition. --- test/nodes/core/function/10-function_spec.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/nodes/core/function/10-function_spec.js b/test/nodes/core/function/10-function_spec.js index d5d35d77e..d11d67b11 100644 --- a/test/nodes/core/function/10-function_spec.js +++ b/test/nodes/core/function/10-function_spec.js @@ -1734,9 +1734,10 @@ describe('function node', function() { msg.delta = Date.now() - msg.payload; receivedMsgs.push(msg) if (receivedMsgs.length === 5) { - var errors = receivedMsgs.filter(msg => msg.delta < timeout_ms) + let deltas = receivedMsgs.map(msg => msg.delta); + var errors = deltas.filter(delta => delta < timeout_ms) if (errors.length > 0) { - done(new Error(`Message received before init completed - was ${msg.delta} expected >${timeout_ms}`)) + done(new Error(`Message received before init completed - delta values ${JSON.stringify(deltas)} expected to be > ${timeout_ms}`)) } else { done(); } From 34e8d2b051ab94e4dfb3f73b5d1311fd56c1c825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20L=C3=B8vdal?= Date: Sun, 24 Sep 2023 18:01:27 +0200 Subject: [PATCH 3/4] Add workaround for timers triggering too early in test --- test/nodes/core/function/10-function_spec.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/nodes/core/function/10-function_spec.js b/test/nodes/core/function/10-function_spec.js index d11d67b11..7a5f2950b 100644 --- a/test/nodes/core/function/10-function_spec.js +++ b/test/nodes/core/function/10-function_spec.js @@ -1719,6 +1719,9 @@ describe('function node', function() { it('should delay handling messages until init completes', function(done) { const timeout_ms = 200; + // Since helper.load uses process.nextTick timers might occasionally finish + // a couple of milliseconds too early, so give some leeway to the check. + const timeout_check_margin = 5; var flow = [{id:"n1",type:"function",wires:[["n2"]],initialize: ` return new Promise((resolve,reject) => { setTimeout(resolve, ${timeout_ms}); @@ -1735,9 +1738,9 @@ describe('function node', function() { receivedMsgs.push(msg) if (receivedMsgs.length === 5) { let deltas = receivedMsgs.map(msg => msg.delta); - var errors = deltas.filter(delta => delta < timeout_ms) + var errors = deltas.filter(delta => delta < (timeout_ms - timeout_check_margin)) if (errors.length > 0) { - done(new Error(`Message received before init completed - delta values ${JSON.stringify(deltas)} expected to be > ${timeout_ms}`)) + done(new Error(`Message received before init completed - delta values ${JSON.stringify(deltas)} expected to be > ${timeout_ms - timeout_check_margin}`)) } else { done(); } From 9091935d773e4a0eb8b57ac1df87334bc9096954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20L=C3=B8vdal?= Date: Mon, 25 Sep 2023 18:53:11 +0200 Subject: [PATCH 4/4] Update variable names --- test/nodes/core/function/10-function_spec.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/nodes/core/function/10-function_spec.js b/test/nodes/core/function/10-function_spec.js index 7a5f2950b..b903f0732 100644 --- a/test/nodes/core/function/10-function_spec.js +++ b/test/nodes/core/function/10-function_spec.js @@ -1718,13 +1718,13 @@ describe('function node', function() { describe("init function", function() { it('should delay handling messages until init completes', function(done) { - const timeout_ms = 200; + const timeoutMS = 200; // Since helper.load uses process.nextTick timers might occasionally finish // a couple of milliseconds too early, so give some leeway to the check. - const timeout_check_margin = 5; + const timeoutCheckMargin = 5; var flow = [{id:"n1",type:"function",wires:[["n2"]],initialize: ` return new Promise((resolve,reject) => { - setTimeout(resolve, ${timeout_ms}); + setTimeout(resolve, ${timeoutMS}); })`, func:"return msg;" }, @@ -1738,9 +1738,9 @@ describe('function node', function() { receivedMsgs.push(msg) if (receivedMsgs.length === 5) { let deltas = receivedMsgs.map(msg => msg.delta); - var errors = deltas.filter(delta => delta < (timeout_ms - timeout_check_margin)) + var errors = deltas.filter(delta => delta < (timeoutMS - timeoutCheckMargin)) if (errors.length > 0) { - done(new Error(`Message received before init completed - delta values ${JSON.stringify(deltas)} expected to be > ${timeout_ms - timeout_check_margin}`)) + done(new Error(`Message received before init completed - delta values ${JSON.stringify(deltas)} expected to be > ${timeoutMS - timeoutCheckMargin}`)) } else { done(); }