mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Increase delay burst test timeout
The test was occasionally timing out, despite it succeeding. Increased the timeout to give it a bit more safety margin to complete
This commit is contained in:
parent
b666734c79
commit
9e91e42a1b
@ -77,7 +77,7 @@ describe('delay Node', function() {
|
|||||||
HOURS : "hours",
|
HOURS : "hours",
|
||||||
DAYS : "days"
|
DAYS : "days"
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells whether two numeric values are close enough to each other
|
* Tells whether two numeric values are close enough to each other
|
||||||
* @param actualValue - the value we're testing
|
* @param actualValue - the value we're testing
|
||||||
@ -89,7 +89,7 @@ describe('delay Node', function() {
|
|||||||
var toleranceFraction = expectedValue * (tolerancePercent/100);
|
var toleranceFraction = expectedValue * (tolerancePercent/100);
|
||||||
var minExpected = expectedValue - toleranceFraction;
|
var minExpected = expectedValue - toleranceFraction;
|
||||||
var maxExpected = expectedValue + toleranceFraction;
|
var maxExpected = expectedValue + toleranceFraction;
|
||||||
|
|
||||||
if(actualValue >= minExpected && actualValue <= maxExpected) {
|
if(actualValue >= minExpected && actualValue <= maxExpected) {
|
||||||
toReturn = true;
|
toReturn = true;
|
||||||
} else {
|
} else {
|
||||||
@ -97,7 +97,7 @@ describe('delay Node', function() {
|
|||||||
}
|
}
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs a delay test
|
* Runs a delay test
|
||||||
* @param aTimeout - the timeout quantity
|
* @param aTimeout - the timeout quantity
|
||||||
@ -115,7 +115,7 @@ describe('delay Node', function() {
|
|||||||
var runtimeNanos = ( (endTime[0] * nanosToSeconds) + endTime[1] );
|
var runtimeNanos = ( (endTime[0] * nanosToSeconds) + endTime[1] );
|
||||||
var runtimeSeconds = runtimeNanos / nanosToSeconds;
|
var runtimeSeconds = runtimeNanos / nanosToSeconds;
|
||||||
var aTimeoutUnifiedToSeconds;
|
var aTimeoutUnifiedToSeconds;
|
||||||
|
|
||||||
// calculating the timeout in seconds
|
// calculating the timeout in seconds
|
||||||
if(aTimeoutUnit == TimeUnitEnum.MILLIS) {
|
if(aTimeoutUnit == TimeUnitEnum.MILLIS) {
|
||||||
aTimeoutUnifiedToSeconds = aTimeout / millisToSeconds;
|
aTimeoutUnifiedToSeconds = aTimeout / millisToSeconds;
|
||||||
@ -128,7 +128,7 @@ describe('delay Node', function() {
|
|||||||
} else if(aTimeoutUnit == TimeUnitEnum.DAYS) {
|
} else if(aTimeoutUnit == TimeUnitEnum.DAYS) {
|
||||||
aTimeoutUnifiedToSeconds = aTimeout * secondsToDays;
|
aTimeoutUnifiedToSeconds = aTimeout * secondsToDays;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(closeEnough(runtimeSeconds, aTimeoutUnifiedToSeconds, GRACE_PERCENTAGE)) {
|
if(closeEnough(runtimeSeconds, aTimeoutUnifiedToSeconds, GRACE_PERCENTAGE)) {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
@ -146,7 +146,7 @@ describe('delay Node', function() {
|
|||||||
delayNode1.receive({payload:"delayMe"});
|
delayNode1.receive({payload:"delayMe"});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We send a message, take a timestamp then when the message is received by the helper node, we take another timestamp.
|
* We send a message, take a timestamp then when the message is received by the helper node, we take another timestamp.
|
||||||
* Then check if the message has been delayed by the expected amount.
|
* Then check if the message has been delayed by the expected amount.
|
||||||
@ -154,23 +154,23 @@ describe('delay Node', function() {
|
|||||||
it('delays the message in seconds', function(done) {
|
it('delays the message in seconds', function(done) {
|
||||||
genericDelayTest(0.5, "seconds", done);
|
genericDelayTest(0.5, "seconds", done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('delays the message in milliseconds', function(done) {
|
it('delays the message in milliseconds', function(done) {
|
||||||
genericDelayTest(500, "milliseconds", done);
|
genericDelayTest(500, "milliseconds", done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('delays the message in minutes', function(done) { // this is also 0.5 seconds
|
it('delays the message in minutes', function(done) { // this is also 0.5 seconds
|
||||||
genericDelayTest(0.00833, "minutes", done);
|
genericDelayTest(0.00833, "minutes", done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('delays the message in hours', function(done) { // this is also 0.5 seconds
|
it('delays the message in hours', function(done) { // this is also 0.5 seconds
|
||||||
genericDelayTest(0.0001388, "hours", done);
|
genericDelayTest(0.0001388, "hours", done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('delays the message in days', function(done) { // this is also 0.5 seconds
|
it('delays the message in days', function(done) { // this is also 0.5 seconds
|
||||||
genericDelayTest(0.000005787, "days", done);
|
genericDelayTest(0.000005787, "days", done);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs a rate limit test - only testing seconds!
|
* Runs a rate limit test - only testing seconds!
|
||||||
* @param aLimit - the message limit count
|
* @param aLimit - the message limit count
|
||||||
@ -184,9 +184,9 @@ describe('delay Node', function() {
|
|||||||
var helperNode1 = helper.getNode("helperNode1");
|
var helperNode1 = helper.getNode("helperNode1");
|
||||||
var receivedMessagesStack = [];
|
var receivedMessagesStack = [];
|
||||||
var rate = 1000/aLimit;
|
var rate = 1000/aLimit;
|
||||||
|
|
||||||
var receiveTimestamp;
|
var receiveTimestamp;
|
||||||
|
|
||||||
helperNode1.on("input", function(msg) {
|
helperNode1.on("input", function(msg) {
|
||||||
if(receiveTimestamp) {
|
if(receiveTimestamp) {
|
||||||
var elapse = process.hrtime(receiveTimestamp);
|
var elapse = process.hrtime(receiveTimestamp);
|
||||||
@ -196,14 +196,14 @@ describe('delay Node', function() {
|
|||||||
receiveTimestamp = process.hrtime();
|
receiveTimestamp = process.hrtime();
|
||||||
receivedMessagesStack.push(msg);
|
receivedMessagesStack.push(msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
var possibleMaxMessageCount = Math.ceil(aLimit * (runtimeInMillis / 1000) + aLimit); // +aLimit as at the start of the 2nd period, we're allowing the 3rd burst
|
var possibleMaxMessageCount = Math.ceil(aLimit * (runtimeInMillis / 1000) + aLimit); // +aLimit as at the start of the 2nd period, we're allowing the 3rd burst
|
||||||
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
for(; i < possibleMaxMessageCount + 1; i++) {
|
for(; i < possibleMaxMessageCount + 1; i++) {
|
||||||
delayNode1.receive({payload:i});
|
delayNode1.receive({payload:i});
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
try {
|
try {
|
||||||
receivedMessagesStack.length.should.be.lessThan(possibleMaxMessageCount);
|
receivedMessagesStack.length.should.be.lessThan(possibleMaxMessageCount);
|
||||||
@ -215,23 +215,23 @@ describe('delay Node', function() {
|
|||||||
} else {
|
} else {
|
||||||
should.fail(null, null, "Received messages were not received in order. Message was " + receivedMessagesStack[i].payload + " on count " + i);
|
should.fail(null, null, "Received messages were not received in order. Message was " + receivedMessagesStack[i].payload + " on count " + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
done(err);
|
done(err);
|
||||||
}
|
}
|
||||||
}, runtimeInMillis);
|
}, runtimeInMillis);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it('limits the message rate to 1 per second', function(done) {
|
it('limits the message rate to 1 per second', function(done) {
|
||||||
genericRateLimitSECONDSTest(1, 1500, done);
|
genericRateLimitSECONDSTest(1, 1500, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
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);
|
this.timeout(6000);
|
||||||
genericRateLimitSECONDSTest(2, 2100, done);
|
genericRateLimitSECONDSTest(2, 2100, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs a rate limit test with drop support - only testing seconds!
|
* Runs a rate limit test with drop support - only testing seconds!
|
||||||
* @param aLimit - the message limit count
|
* @param aLimit - the message limit count
|
||||||
@ -244,11 +244,11 @@ describe('delay Node', function() {
|
|||||||
var delayNode1 = helper.getNode("delayNode1");
|
var delayNode1 = helper.getNode("delayNode1");
|
||||||
var helperNode1 = helper.getNode("helperNode1");
|
var helperNode1 = helper.getNode("helperNode1");
|
||||||
var receivedMessagesStack = [];
|
var receivedMessagesStack = [];
|
||||||
|
|
||||||
var rate = 1000/aLimit;
|
var rate = 1000/aLimit;
|
||||||
|
|
||||||
var receiveTimestamp;
|
var receiveTimestamp;
|
||||||
|
|
||||||
helperNode1.on("input", function(msg) {
|
helperNode1.on("input", function(msg) {
|
||||||
if(receiveTimestamp) {
|
if(receiveTimestamp) {
|
||||||
var elapse = process.hrtime(receiveTimestamp);
|
var elapse = process.hrtime(receiveTimestamp);
|
||||||
@ -258,9 +258,9 @@ describe('delay Node', function() {
|
|||||||
receiveTimestamp = process.hrtime();
|
receiveTimestamp = process.hrtime();
|
||||||
receivedMessagesStack.push(msg);
|
receivedMessagesStack.push(msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
var possibleMaxMessageCount = Math.ceil(aLimit * (runtimeInMillis / 1000) + aLimit); // +aLimit as at the start of the 2nd period, we're allowing the 3rd burst
|
var possibleMaxMessageCount = Math.ceil(aLimit * (runtimeInMillis / 1000) + aLimit); // +aLimit as at the start of the 2nd period, we're allowing the 3rd burst
|
||||||
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
delayNode1.receive({payload:i});
|
delayNode1.receive({payload:i});
|
||||||
i++;
|
i++;
|
||||||
@ -269,12 +269,12 @@ describe('delay Node', function() {
|
|||||||
delayNode1.receive({payload:i});
|
delayNode1.receive({payload:i});
|
||||||
}, 2 * ((rate * i) / possibleMaxMessageCount) );
|
}, 2 * ((rate * i) / possibleMaxMessageCount) );
|
||||||
}
|
}
|
||||||
|
|
||||||
//we need to send a message delayed so that it doesn't get dropped
|
//we need to send a message delayed so that it doesn't get dropped
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
delayNode1.receive({payload:++i});
|
delayNode1.receive({payload:++i});
|
||||||
}, runtimeInMillis - 300); // should give enough time to squeeze another message in
|
}, runtimeInMillis - 300); // should give enough time to squeeze another message in
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
try {
|
try {
|
||||||
receivedMessagesStack.length.should.be.lessThan(possibleMaxMessageCount + 1);
|
receivedMessagesStack.length.should.be.lessThan(possibleMaxMessageCount + 1);
|
||||||
@ -296,17 +296,17 @@ describe('delay Node', function() {
|
|||||||
}, runtimeInMillis);
|
}, runtimeInMillis);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it('limits the message rate to 1 per second, 4 seconds, with drop', function(done) {
|
it('limits the message rate to 1 per second, 4 seconds, with drop', function(done) {
|
||||||
this.timeout(6000);
|
this.timeout(6000);
|
||||||
dropRateLimitSECONDSTest(1, 4000, done);
|
dropRateLimitSECONDSTest(1, 4000, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('limits the message rate to 2 per second, 5 seconds, with drop', function(done) {
|
it('limits the message rate to 2 per second, 5 seconds, with drop', function(done) {
|
||||||
this.timeout(6000);
|
this.timeout(6000);
|
||||||
dropRateLimitSECONDSTest(2, 5000, done);
|
dropRateLimitSECONDSTest(2, 5000, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the actualTimeout is gracefully in between the timeoutFrom and timeoutTo
|
* Returns true if the actualTimeout is gracefully in between the timeoutFrom and timeoutTo
|
||||||
* values. Gracefully means that inBetween could actually mean smaller/greater values
|
* values. Gracefully means that inBetween could actually mean smaller/greater values
|
||||||
@ -327,7 +327,7 @@ describe('delay Node', function() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs a RANDOM DELAY test, checks if the delay is in between the given timeout values
|
* Runs a RANDOM DELAY test, checks if the delay is in between the given timeout values
|
||||||
* @param aTimeoutFrom - the timeout quantity which is the minimal acceptable wait period
|
* @param aTimeoutFrom - the timeout quantity which is the minimal acceptable wait period
|
||||||
@ -347,7 +347,7 @@ describe('delay Node', function() {
|
|||||||
var runtimeSeconds = runtimeNanos / nanosToSeconds;
|
var runtimeSeconds = runtimeNanos / nanosToSeconds;
|
||||||
var aTimeoutFromUnifiedToSeconds;
|
var aTimeoutFromUnifiedToSeconds;
|
||||||
var aTimeoutToUnifiedToSeconds;
|
var aTimeoutToUnifiedToSeconds;
|
||||||
|
|
||||||
// calculating the timeout in seconds
|
// calculating the timeout in seconds
|
||||||
if(aTimeoutUnit == TimeUnitEnum.MILLIS) {
|
if(aTimeoutUnit == TimeUnitEnum.MILLIS) {
|
||||||
aTimeoutFromUnifiedToSeconds = aTimeoutFrom / millisToSeconds;
|
aTimeoutFromUnifiedToSeconds = aTimeoutFrom / millisToSeconds;
|
||||||
@ -365,7 +365,7 @@ describe('delay Node', function() {
|
|||||||
aTimeoutFromUnifiedToSeconds = aTimeoutFrom * secondsToDays;
|
aTimeoutFromUnifiedToSeconds = aTimeoutFrom * secondsToDays;
|
||||||
aTimeoutToUnifiedToSeconds = aTimeoutTo * secondsToDays;
|
aTimeoutToUnifiedToSeconds = aTimeoutTo * secondsToDays;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(inBetweenDelays(aTimeoutFromUnifiedToSeconds, aTimeoutToUnifiedToSeconds, runtimeSeconds, GRACE_PERCENTAGE)) {
|
if(inBetweenDelays(aTimeoutFromUnifiedToSeconds, aTimeoutToUnifiedToSeconds, runtimeSeconds, GRACE_PERCENTAGE)) {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
@ -383,48 +383,48 @@ describe('delay Node', function() {
|
|||||||
delayNode1.receive({payload:"delayMe"});
|
delayNode1.receive({payload:"delayMe"});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it('randomly delays the message in seconds', function(done) {
|
it('randomly delays the message in seconds', function(done) {
|
||||||
randomDelayTest(0.4, 0.8, "seconds", done);
|
randomDelayTest(0.4, 0.8, "seconds", done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('randomly delays the message in milliseconds', function(done) {
|
it('randomly delays the message in milliseconds', function(done) {
|
||||||
randomDelayTest("400", "800", "milliseconds", done);
|
randomDelayTest("400", "800", "milliseconds", done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('randomly delays the message in minutes', function(done) {
|
it('randomly delays the message in minutes', function(done) {
|
||||||
randomDelayTest(0.0066, 0.0133, "minutes", done);
|
randomDelayTest(0.0066, 0.0133, "minutes", done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('delays the message in hours', function(done) {
|
it('delays the message in hours', function(done) {
|
||||||
randomDelayTest(0.000111111, 0.000222222, "hours", done);
|
randomDelayTest(0.000111111, 0.000222222, "hours", done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('delays the message in days', function(done) {
|
it('delays the message in days', function(done) {
|
||||||
randomDelayTest(0.0000046296, 0.0000092593, "days", done);
|
randomDelayTest(0.0000046296, 0.0000092593, "days", done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles bursts using a buffer', function(done) {
|
it('handles bursts using a buffer', function(done) {
|
||||||
this.timeout(6000);
|
this.timeout(8000);
|
||||||
|
|
||||||
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() {
|
||||||
var delayNode1 = helper.getNode("delayNode1");
|
var delayNode1 = helper.getNode("delayNode1");
|
||||||
var helperNode1 = helper.getNode("helperNode1");
|
var helperNode1 = helper.getNode("helperNode1");
|
||||||
|
|
||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
|
|
||||||
var receivedWarning = false;
|
var receivedWarning = false;
|
||||||
var messageBurstSize = 1500;
|
var messageBurstSize = 1500;
|
||||||
|
|
||||||
// we ensure that we note that a warning is received for buffer growth
|
// we ensure that we note that a warning is received for buffer growth
|
||||||
sinon.stub(delayNode1, 'warn', function(warning){
|
sinon.stub(delayNode1, 'warn', function(warning){
|
||||||
if(warning.indexOf("buffer exceeded 1000 messages" > -1)) {
|
if(warning.indexOf("buffer exceeded 1000 messages" > -1)) {
|
||||||
receivedWarning = true;
|
receivedWarning = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// we ensure that the warning is received for buffer size and that we get the last message
|
// we ensure that the warning is received for buffer size and that we get the last message
|
||||||
helperNode1.on("input", function(msg) {
|
helperNode1.on("input", function(msg) {
|
||||||
if(msg.payload === (messageBurstSize - 1) && receivedWarning === true) {
|
if(msg.payload === (messageBurstSize - 1) && receivedWarning === true) {
|
||||||
@ -433,7 +433,7 @@ describe('delay Node', function() {
|
|||||||
});
|
});
|
||||||
// send 1500 messages as quickly as possible
|
// send 1500 messages as quickly as possible
|
||||||
for(var i = 0; i < messageBurstSize; i++) {
|
for(var i = 0; i < messageBurstSize; i++) {
|
||||||
delayNode1.receive({payload:i});
|
delayNode1.receive({payload:i});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user