From a2b95dbb397ef656641a4a97d123b27a16436e2a Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Fri, 16 Jul 2021 11:31:21 +0100 Subject: [PATCH] delay node - change lifo property to toFront add info to sidebar add tests --- .../@node-red/nodes/core/function/89-delay.js | 2 +- .../locales/en-US/function/89-delay.html | 5 ++ test/nodes/core/function/89-delay_spec.js | 56 +++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/nodes/core/function/89-delay.js b/packages/node_modules/@node-red/nodes/core/function/89-delay.js index 850497e22..5e90edaac 100644 --- a/packages/node_modules/@node-red/nodes/core/function/89-delay.js +++ b/packages/node_modules/@node-red/nodes/core/function/89-delay.js @@ -253,7 +253,7 @@ module.exports = function(RED) { if ((max_msgs > 0) && (node.buffer.length >= max_msgs)) { node.buffer = []; node.error(RED._("delay.errors.too-many"), msg); - } else if (msg.lifo) { + } else if (msg.toFront === true) { node.buffer.unshift({msg: m, send: send, done: done}); node.reportDepth(); } else { diff --git a/packages/node_modules/@node-red/nodes/locales/en-US/function/89-delay.html b/packages/node_modules/@node-red/nodes/locales/en-US/function/89-delay.html index 1e801698a..574afd24f 100644 --- a/packages/node_modules/@node-red/nodes/locales/en-US/function/89-delay.html +++ b/packages/node_modules/@node-red/nodes/locales/en-US/function/89-delay.html @@ -35,6 +35,11 @@
If the received message has this property set to a numeric value then that many messages will be released immediately. If set to any other type (e.g. boolean), then all outstanding messages held by the node are sent immediately.
+
toFront
+
When in rate limit mode, if the received message has this property set to boolean true, + then the message is pushed to the front of the queue and will be released next. + This can be used in combination with msg.flush=1 to resend immediately. +

Details

When configured to delay messages, the delay interval can be a fixed value, diff --git a/test/nodes/core/function/89-delay_spec.js b/test/nodes/core/function/89-delay_spec.js index 87ca9c434..4c1ac9dbc 100644 --- a/test/nodes/core/function/89-delay_spec.js +++ b/test/nodes/core/function/89-delay_spec.js @@ -789,6 +789,62 @@ describe('delay Node', function() { }); }); + it('can part push to front of rate limit queue', function(done) { + this.timeout(2000); + var flow = [{"id":"delayNode1","type":"delay","name":"delayNode","pauseType":"rate","timeout":1,"timeoutUnits":"seconds","rate":1,"rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"wires":[["helperNode1"]]}, + {id:"helperNode1", type:"helper", wires:[]}]; + helper.load(delayNode, flow, function() { + var delayNode1 = helper.getNode("delayNode1"); + var helperNode1 = helper.getNode("helperNode1"); + var t = Date.now(); + var c = 0; + helperNode1.on("input", function(msg) { + msg.should.have.a.property('payload'); + msg.should.have.a.property('topic'); + try { + if (msg.topic === "aoo") { + msg.payload.should.equal(1); + (Date.now() - t).should.be.approximately(2,50); + c = c + 1; + } + else if (msg.topic === "eoo") { + msg.payload.should.equal(1); + (Date.now() - t).should.be.approximately(4,50); + c = c + 1; + } + else if (msg.topic === "coo") { + msg.payload.should.equal(1); + (Date.now() - t).should.be.approximately(202,50); + c = c + 1; + } + else if (msg.topic === "boo") { + msg.payload.should.equal(1); + (Date.now() - t).should.be.approximately(406,50); + c = c + 1; + } + else if (msg.topic === "doo") { + msg.payload.should.equal(1); + (Date.now() - t).should.be.approximately(404,50); + c = c + 1; + } + if (c === 5) { done(); } + } catch(e) { + done(e); + } + }); + + // send test messages + delayNode1.receive({payload:1,topic:"aoo"}); + setImmediate( function() { delayNode1.receive({payload:1,topic:"boo"}); } ); + setImmediate( function() { delayNode1.receive({payload:1,topic:"coo",toFront:true}); } ); + setImmediate( function() { delayNode1.receive({payload:1,topic:"doo"}); } ); + setImmediate( function() { delayNode1.receive({payload:1,topic:"eoo",toFront:true}); } ); + setImmediate( function() { delayNode1.receive({flush:1}); }); + setTimeout( function() { delayNode1.receive({flush:1}); }, 200); + setTimeout( function() { delayNode1.receive({flush:4}); }, 400); + }); + }); + it('can reset rate limit queue', function(done) { this.timeout(2000); var flow = [{"id":"delayNode1","type":"delay","name":"delayNode","pauseType":"rate","timeout":1,"timeoutUnits":"seconds","rate":2,"rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"wires":[["helperNode1"]]},