From d407f31ae57dba93b636b832ae32ab69be273180 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Fri, 9 Jun 2017 19:42:12 +0100 Subject: [PATCH] stop delay node spamming web socket (when in fast rate limit mode) --- nodes/core/core/89-delay.js | 17 ++++++-------- test/nodes/core/core/89-delay_spec.js | 34 --------------------------- 2 files changed, 7 insertions(+), 44 deletions(-) diff --git a/nodes/core/core/89-delay.js b/nodes/core/core/89-delay.js index 5970333b5..96928fc97 100644 --- a/nodes/core/core/89-delay.js +++ b/nodes/core/core/89-delay.js @@ -126,16 +126,14 @@ module.exports = function(RED) { if (!node.drop) { if ( node.intervalID !== -1) { node.buffer.push(msg); - if (node.buffer.length > 0) { + if ((node.rate >= 200) && (node.buffer.length > 0)) { node.status({text:node.buffer.length}); } - if ((node.buffer.length > 1000) && (olddepth < 1000)) { - olddepth = 1000; - node.warn(node.name + " " + RED._("delay.error.buffer")); - } - if ((node.buffer.length > 10000) && (olddepth < 10000)) { - olddepth = 10000; - node.warn(node.name + " " + RED._("delay.error.buffer1")); + else { + if (!olddepth) { + node.status({fill:"blue",shape:"dot"}); + olddepth = 1; + } } } else { @@ -145,11 +143,10 @@ module.exports = function(RED) { clearInterval(node.intervalID); node.intervalID = -1; node.status({}); + olddepth = 0; } if (node.buffer.length > 0) { node.send(node.buffer.shift()); - if (node.buffer.length < 1000) { olddepth = 0; } - node.status({text:node.buffer.length}); } },node.rate); } diff --git a/test/nodes/core/core/89-delay_spec.js b/test/nodes/core/core/89-delay_spec.js index 43523f00a..8c7c7b0e6 100644 --- a/test/nodes/core/core/89-delay_spec.js +++ b/test/nodes/core/core/89-delay_spec.js @@ -484,40 +484,6 @@ describe('delay Node', function() { randomDelayTest(0.0000046296, 0.0000092593, "days", done); }); - it('handles bursts using a buffer', function(done) { - this.timeout(10000); - - var flow = [{"id":"delayNode1","type":"delay","name":"delayNode","pauseType":"rate","timeout":5,"timeoutUnits":"seconds","rate":1000,"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 sinon = require('sinon'); - var receivedWarning = false; - var messageBurstSize = 1200; - - // we ensure that we note that a warning is received for buffer growth - sinon.stub(delayNode1, 'warn', function(warning) { - receivedWarning = true; - }); - // we ensure that the warning is received for buffer size and that we get the last message - helperNode1.on("input", function(msg) { - if (msg.payload === (messageBurstSize - 1)) { - try { - receivedWarning.should.be.true(); - done(); - } catch(err) { - done(err); - } - } - }); - // send messages as quickly as possible - for (var i = 0; i < messageBurstSize; i++) { - delayNode1.receive({payload:i}); - } - }); - }); - it('handles delay queue', function(done) { this.timeout(2000); var flow = [{id:"delayNode1", type :"delay","name":"delayNode","nbRateUnits":"1","pauseType":"queue","timeout":1,"timeoutUnits":"seconds","rate":4,"rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"wires":[["helperNode1"]]},