mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
parent
083dc213f0
commit
c91a3f3f78
@ -132,15 +132,15 @@ module.exports = function(RED) {
|
|||||||
},node.rate);
|
},node.rate);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var now;
|
var timeSinceLast;
|
||||||
if (node.lastSent) {
|
if (node.lastSent) {
|
||||||
now = process.hrtime(node.lastSent);
|
timeSinceLast = process.hrtime(node.lastSent);
|
||||||
}
|
}
|
||||||
if (!node.lastSent) { // ensuring that we always send the first message
|
if (!node.lastSent) { // ensuring that we always send the first message
|
||||||
node.lastSent = process.hrtime();
|
node.lastSent = process.hrtime();
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
} else if ( ( (now[0] * SECONDS_TO_NANOS) + now[1] ) > (node.rate * MILLIS_TO_NANOS) ) {
|
} else if ( ( (timeSinceLast[0] * SECONDS_TO_NANOS) + timeSinceLast[1] ) > (node.rate * MILLIS_TO_NANOS) ) {
|
||||||
node.lastSent = now;
|
node.lastSent = process.hrtime();
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,15 +218,18 @@ describe('delayNode', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('limits the message rate to 2 per second, 2 seconds', function(done) {
|
it('limits the message rate to 2 per second, 2 seconds', function(done) {
|
||||||
|
this.timeout(6000);
|
||||||
genericRateLimitSECONDSTest(2, false, 2100, done);
|
genericRateLimitSECONDSTest(2, false, 2100, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('limits the message rate to 1 per second, 2 seconds, with drop', function(done) {
|
it('limits the message rate to 1 per second, 2 seconds, with drop', function(done) {
|
||||||
|
this.timeout(6000);
|
||||||
genericRateLimitSECONDSTest(1, true, 2300, done);
|
genericRateLimitSECONDSTest(1, true, 2300, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('limits the message rate to 2 per second, 2 seconds, with drop', function(done) {
|
it('limits the message rate to 2 per second, 5 seconds, with drop', function(done) {
|
||||||
genericRateLimitSECONDSTest(2, true, 2300, done);
|
this.timeout(6000);
|
||||||
|
genericRateLimitSECONDSTest(2, true, 5000, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -327,6 +330,8 @@ describe('delayNode', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('handles bursts using a buffer', function(done) {
|
it('handles bursts using a buffer', function(done) {
|
||||||
|
this.timeout(6000);
|
||||||
|
|
||||||
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"]]},
|
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:[]}];
|
{id:"helperNode1", type:"helper", wires:[]}];
|
||||||
helper.load(delayNode, flow, function() {
|
helper.load(delayNode, flow, function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user