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(); }