1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

Make tests more robust and print more details if one might still fail

This commit is contained in:
Ruben Bridgewater
2016-03-07 11:52:48 +01:00
parent 7ddb955517
commit 2913eaccaf
2 changed files with 14 additions and 6 deletions

View File

@@ -213,8 +213,11 @@ describe("connection tests", function () {
client.on('error', function(err) { client.on('error', function(err) {
assert(/Redis connection in broken state: connection timeout.*?exceeded./.test(err.message)); assert(/Redis connection in broken state: connection timeout.*?exceeded./.test(err.message));
assert(Date.now() - time < connect_timeout + 25); // The code execution on windows is very slow at times
assert(Date.now() - time >= connect_timeout - 3); // Timers sometimes trigger early (e.g. 1ms to early) var now = Date.now();
assert(now - time < connect_timeout + 50, 'The real timeout time should be below ' + (connect_timeout + 50) + 'ms but is: ' + (now - time));
// Timers sometimes trigger early (e.g. 1ms to early)
assert(now - time >= connect_timeout - 3, 'The real timeout time should be above ' + connect_timeout + 'ms, but it is: ' + (now - time));
done(); done();
}); });
}); });
@@ -464,9 +467,9 @@ describe("connection tests", function () {
}; };
client.on("ready", function () { client.on("ready", function () {
var rest = Date.now() - time; var rest = Date.now() - time;
assert(rest >= 500); assert(rest >= 498, 'Rest should be equal or above 500 ms but is: ' + rest); // setTimeout might trigger early
// Be on the safe side and accept 200ms above the original value // Be on the safe side and accept 200ms above the original value
assert(rest - 200 < 500); assert(rest - 200 < 500, 'Rest - 200 should be below 500 ms but is: ' + (rest - 200));
assert(delayed); assert(delayed);
end(); end();
}); });
@@ -495,9 +498,9 @@ describe("connection tests", function () {
}; };
client.on("ready", function () { client.on("ready", function () {
var rest = Date.now() - time; var rest = Date.now() - time;
assert(rest >= 1000); assert(rest >= 998, '`rest` should be equal or above 1000 ms but is: ' + rest); // setTimeout might trigger early
// Be on the safe side and accept 200ms above the original value // Be on the safe side and accept 200ms above the original value
assert(rest - 200 < 1000); assert(rest - 200 < 1000, '`rest` - 200 should be below 1000 ms but is: ' + (rest - 200));
assert(delayed); assert(delayed);
end(); end();
}); });

View File

@@ -591,6 +591,11 @@ describe("The node_redis client", function () {
return done(); return done();
} }
}); });
client.on('error', function (err) {
// This is rare but it might be triggered.
// So let's have a robust test
assert.strictEqual(err.code, 'ECONNRESET');
});
}); });
}); });