1
0
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:
Nick O'Leary 2015-10-03 09:04:57 +01:00
parent b666734c79
commit 9e91e42a1b

View File

@ -77,7 +77,7 @@ describe('delay Node', function() {
HOURS : "hours",
DAYS : "days"
}
/**
* Tells whether two numeric values are close enough to each other
* @param actualValue - the value we're testing
@ -89,7 +89,7 @@ describe('delay Node', function() {
var toleranceFraction = expectedValue * (tolerancePercent/100);
var minExpected = expectedValue - toleranceFraction;
var maxExpected = expectedValue + toleranceFraction;
if(actualValue >= minExpected && actualValue <= maxExpected) {
toReturn = true;
} else {
@ -97,7 +97,7 @@ describe('delay Node', function() {
}
return toReturn;
}
/**
* Runs a delay test
* @param aTimeout - the timeout quantity
@ -115,7 +115,7 @@ describe('delay Node', function() {
var runtimeNanos = ( (endTime[0] * nanosToSeconds) + endTime[1] );
var runtimeSeconds = runtimeNanos / nanosToSeconds;
var aTimeoutUnifiedToSeconds;
// calculating the timeout in seconds
if(aTimeoutUnit == TimeUnitEnum.MILLIS) {
aTimeoutUnifiedToSeconds = aTimeout / millisToSeconds;
@ -128,7 +128,7 @@ describe('delay Node', function() {
} else if(aTimeoutUnit == TimeUnitEnum.DAYS) {
aTimeoutUnifiedToSeconds = aTimeout * secondsToDays;
}
if(closeEnough(runtimeSeconds, aTimeoutUnifiedToSeconds, GRACE_PERCENTAGE)) {
done();
} else {
@ -146,7 +146,7 @@ describe('delay Node', function() {
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.
* 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) {
genericDelayTest(0.5, "seconds", done);
});
it('delays the message in milliseconds', function(done) {
genericDelayTest(500, "milliseconds", done);
});
it('delays the message in minutes', function(done) { // this is also 0.5 seconds
genericDelayTest(0.00833, "minutes", done);
});
it('delays the message in hours', function(done) { // this is also 0.5 seconds
genericDelayTest(0.0001388, "hours", done);
});
it('delays the message in days', function(done) { // this is also 0.5 seconds
genericDelayTest(0.000005787, "days", done);
});
/**
* Runs a rate limit test - only testing seconds!
* @param aLimit - the message limit count
@ -184,9 +184,9 @@ describe('delay Node', function() {
var helperNode1 = helper.getNode("helperNode1");
var receivedMessagesStack = [];
var rate = 1000/aLimit;
var receiveTimestamp;
helperNode1.on("input", function(msg) {
if(receiveTimestamp) {
var elapse = process.hrtime(receiveTimestamp);
@ -196,14 +196,14 @@ describe('delay Node', function() {
receiveTimestamp = process.hrtime();
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 i = 0;
for(; i < possibleMaxMessageCount + 1; i++) {
delayNode1.receive({payload:i});
}
setTimeout(function() {
try {
receivedMessagesStack.length.should.be.lessThan(possibleMaxMessageCount);
@ -215,23 +215,23 @@ describe('delay Node', function() {
} else {
should.fail(null, null, "Received messages were not received in order. Message was " + receivedMessagesStack[i].payload + " on count " + i);
}
}
}
} catch (err) {
done(err);
}
}, runtimeInMillis);
});
}
it('limits the message rate to 1 per second', function(done) {
genericRateLimitSECONDSTest(1, 1500, done);
});
it('limits the message rate to 2 per second, 2 seconds', function(done) {
this.timeout(6000);
genericRateLimitSECONDSTest(2, 2100, done);
});
/**
* Runs a rate limit test with drop support - only testing seconds!
* @param aLimit - the message limit count
@ -244,11 +244,11 @@ describe('delay Node', function() {
var delayNode1 = helper.getNode("delayNode1");
var helperNode1 = helper.getNode("helperNode1");
var receivedMessagesStack = [];
var rate = 1000/aLimit;
var receiveTimestamp;
helperNode1.on("input", function(msg) {
if(receiveTimestamp) {
var elapse = process.hrtime(receiveTimestamp);
@ -258,9 +258,9 @@ describe('delay Node', function() {
receiveTimestamp = process.hrtime();
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 i = 0;
delayNode1.receive({payload:i});
i++;
@ -269,12 +269,12 @@ describe('delay Node', function() {
delayNode1.receive({payload:i});
}, 2 * ((rate * i) / possibleMaxMessageCount) );
}
//we need to send a message delayed so that it doesn't get dropped
setTimeout(function() {
delayNode1.receive({payload:++i});
}, runtimeInMillis - 300); // should give enough time to squeeze another message in
setTimeout(function() {
try {
receivedMessagesStack.length.should.be.lessThan(possibleMaxMessageCount + 1);
@ -296,17 +296,17 @@ describe('delay Node', function() {
}, runtimeInMillis);
});
}
it('limits the message rate to 1 per second, 4 seconds, with drop', function(done) {
this.timeout(6000);
dropRateLimitSECONDSTest(1, 4000, done);
});
it('limits the message rate to 2 per second, 5 seconds, with drop', function(done) {
this.timeout(6000);
dropRateLimitSECONDSTest(2, 5000, done);
});
/**
* Returns true if the actualTimeout is gracefully in between the timeoutFrom and timeoutTo
* values. Gracefully means that inBetween could actually mean smaller/greater values
@ -327,7 +327,7 @@ describe('delay Node', function() {
return false;
}
}
/**
* 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
@ -347,7 +347,7 @@ describe('delay Node', function() {
var runtimeSeconds = runtimeNanos / nanosToSeconds;
var aTimeoutFromUnifiedToSeconds;
var aTimeoutToUnifiedToSeconds;
// calculating the timeout in seconds
if(aTimeoutUnit == TimeUnitEnum.MILLIS) {
aTimeoutFromUnifiedToSeconds = aTimeoutFrom / millisToSeconds;
@ -365,7 +365,7 @@ describe('delay Node', function() {
aTimeoutFromUnifiedToSeconds = aTimeoutFrom * secondsToDays;
aTimeoutToUnifiedToSeconds = aTimeoutTo * secondsToDays;
}
if(inBetweenDelays(aTimeoutFromUnifiedToSeconds, aTimeoutToUnifiedToSeconds, runtimeSeconds, GRACE_PERCENTAGE)) {
done();
} else {
@ -383,48 +383,48 @@ describe('delay Node', function() {
delayNode1.receive({payload:"delayMe"});
});
}
it('randomly delays the message in seconds', function(done) {
randomDelayTest(0.4, 0.8, "seconds", done);
});
it('randomly delays the message in milliseconds', function(done) {
randomDelayTest("400", "800", "milliseconds", done);
});
it('randomly delays the message in minutes', function(done) {
randomDelayTest(0.0066, 0.0133, "minutes", done);
});
it('delays the message in hours', function(done) {
randomDelayTest(0.000111111, 0.000222222, "hours", done);
});
it('delays the message in days', function(done) {
randomDelayTest(0.0000046296, 0.0000092593, "days", 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"]]},
{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 = 1500;
// we ensure that we note that a warning is received for buffer growth
sinon.stub(delayNode1, 'warn', function(warning){
if(warning.indexOf("buffer exceeded 1000 messages" > -1)) {
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) && receivedWarning === true) {
@ -433,7 +433,7 @@ describe('delay Node', function() {
});
// send 1500 messages as quickly as possible
for(var i = 0; i < messageBurstSize; i++) {
delayNode1.receive({payload:i});
delayNode1.receive({payload:i});
}
});
});