mirror of
https://github.com/node-red/node-red
synced 2024-11-21 23:48:30 +00:00
Merge pull request #4940 from node-red/Delay-node-not-send-on-reset-if-queue-empty
Make delay node rate limit reset consistent - not send on reset.
This commit is contained in:
commit
e48607c743
@ -253,7 +253,13 @@ module.exports = function(RED) {
|
|||||||
if (node.allowrate && m.hasOwnProperty("rate") && !isNaN(parseFloat(m.rate))) {
|
if (node.allowrate && m.hasOwnProperty("rate") && !isNaN(parseFloat(m.rate))) {
|
||||||
node.rate = m.rate;
|
node.rate = m.rate;
|
||||||
}
|
}
|
||||||
send(m);
|
if (msg.hasOwnProperty("reset")) {
|
||||||
|
if (msg.hasOwnProperty("flush")) {
|
||||||
|
node.buffer.push({msg: m, send: send, done: done});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { send(m); }
|
||||||
|
|
||||||
node.reportDepth();
|
node.reportDepth();
|
||||||
node.intervalID = setInterval(sendMsgFromBuffer, node.rate);
|
node.intervalID = setInterval(sendMsgFromBuffer, node.rate);
|
||||||
done();
|
done();
|
||||||
@ -303,7 +309,8 @@ module.exports = function(RED) {
|
|||||||
node.droppedMsgs++;
|
node.droppedMsgs++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (node.allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate))) {
|
if (node.allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate))) {
|
||||||
node.rate = msg.rate;
|
node.rate = msg.rate;
|
||||||
}
|
}
|
||||||
|
@ -1009,6 +1009,29 @@ describe('delay Node', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('sending a msg with reset to empty queue doesnt send anything', 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"]]},
|
||||||
|
{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) {
|
||||||
|
console.log("Shold not get here")
|
||||||
|
done(e);
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout( function() {
|
||||||
|
if (c === 0) { done(); }
|
||||||
|
}, 250);
|
||||||
|
|
||||||
|
// send test messages
|
||||||
|
delayNode1.receive({payload:1,topic:"foo",reset:true}); // send something with blank topic
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
/* Messaging API support */
|
/* Messaging API support */
|
||||||
function mapiDoneTestHelper(done, pauseType, drop, msgAndTimings) {
|
function mapiDoneTestHelper(done, pauseType, drop, msgAndTimings) {
|
||||||
const completeNode = require("nr-test-utils").require("@node-red/nodes/core/common/24-complete.js");
|
const completeNode = require("nr-test-utils").require("@node-red/nodes/core/common/24-complete.js");
|
||||||
|
Loading…
Reference in New Issue
Block a user