mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
let default apply if msg.delay not set in override mode. (#1397)
* let default apply if msg.delay not set in override mode. * Update tests to match * allow msg.delay to be 0 if wanted and test for that
This commit is contained in:
parent
53bfe12ac1
commit
ae7c298b1a
@ -102,7 +102,7 @@
|
||||
<dt class="optional">delay <span class="property-type">number</span></dt>
|
||||
<dd>Sets the delay, in milliseconds, to be applied to the message. This
|
||||
option only applies if the node is configured to allow the message to
|
||||
provide the delay interval.</dd>
|
||||
override the configured default delay interval.</dd>
|
||||
<dt class="optional">reset</dt>
|
||||
<dd>If the received message has this property set to any value, all
|
||||
outstanding messages held by the node are cleared without being sent.</dd>
|
||||
@ -260,7 +260,7 @@
|
||||
$("#delay-details-for").show();
|
||||
$("#random-details").hide();
|
||||
} else if (this.value === "delayv") {
|
||||
$("#delay-details-for").hide();
|
||||
$("#delay-details-for").show();
|
||||
$("#random-details").hide();
|
||||
} else if (this.value === "random") {
|
||||
$("#delay-details-for").hide();
|
||||
|
@ -105,7 +105,10 @@ module.exports = function(RED) {
|
||||
}
|
||||
else if (node.pauseType === "delayv") {
|
||||
node.on("input", function(msg) {
|
||||
var delayvar = Number(msg.delay || 0);
|
||||
var delayvar = Number(node.timeout);
|
||||
if (msg.hasOwnProperty("delay") && !isNaN(parseFloat(msg.delay))) {
|
||||
delayvar = parseFloat(msg.delay);
|
||||
}
|
||||
if (delayvar < 0) { delayvar = 0; }
|
||||
var id = setTimeout(function() {
|
||||
node.idList.splice(node.idList.indexOf(id),1);
|
||||
@ -113,7 +116,7 @@ module.exports = function(RED) {
|
||||
node.send(msg);
|
||||
}, delayvar);
|
||||
node.idList.push(id);
|
||||
if ((delayvar >= 1) && (node.idList.length !== 0)) {
|
||||
if ((delayvar >= 0) && (node.idList.length !== 0)) {
|
||||
node.status({fill:"blue",shape:"dot",text:delayvar/1000+"s"});
|
||||
}
|
||||
if (msg.hasOwnProperty("reset")) { clearDelayList(); }
|
||||
|
@ -204,7 +204,7 @@
|
||||
"for": "For",
|
||||
"delaymsg": "Delay each message",
|
||||
"delayfixed": "Fixed delay",
|
||||
"delayvarmsg": "Set delay with msg.delay",
|
||||
"delayvarmsg": "Override delay with msg.delay",
|
||||
"randomdelay": "Random delay",
|
||||
"limitrate": "Rate Limit",
|
||||
"limitall": "All messages",
|
||||
|
@ -347,7 +347,7 @@ describe('delay Node', function() {
|
||||
* @param delay - the variable delay: milliseconds
|
||||
*/
|
||||
function variableDelayTest(aTimeoutFrom, aTimeoutTo, aTimeoutUnit, delay, done) {
|
||||
var flow = [{"id":"delayNode1","type":"delay","name":"delayNode","pauseType":"delayv","timeout":5,"timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":aTimeoutFrom,"randomLast":aTimeoutTo,"randomUnits":aTimeoutUnit,"drop":false,"wires":[["helperNode1"]]},
|
||||
var flow = [{"id":"delayNode1","type":"delay","name":"delayNode","pauseType":"delayv","timeout":0.5,"timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":aTimeoutFrom,"randomLast":aTimeoutTo,"randomUnits":aTimeoutUnit,"drop":false,"wires":[["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper", wires:[]}];
|
||||
helper.load(delayNode, flow, function() {
|
||||
var delayNode1 = helper.getNode("delayNode1");
|
||||
@ -400,12 +400,16 @@ describe('delay Node', function() {
|
||||
variableDelayTest("200", "300", "milliseconds", 250, done);
|
||||
});
|
||||
|
||||
it('variable delay is zero if msg.delay not specified', function(done) {
|
||||
variableDelayTest("0", "50", "milliseconds", null, done);
|
||||
it('variable delay is the default if msg.delay not specified', function(done) {
|
||||
variableDelayTest("450", "550", "milliseconds", null, done);
|
||||
});
|
||||
|
||||
it('variable delay is zero if msg.delay is zero', function(done) {
|
||||
variableDelayTest("0", "20", "milliseconds", 0, done);
|
||||
});
|
||||
|
||||
it('variable delay is zero if msg.delay is negative', function(done) {
|
||||
variableDelayTest("0", "50", "milliseconds", -250, done);
|
||||
variableDelayTest("0", "20", "milliseconds", -250, done);
|
||||
});
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user