Skip to content

Commit 2913eac

Browse files
author
Ruben Bridgewater
committed
Make tests more robust and print more details if one might still fail
1 parent 7ddb955 commit 2913eac

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

test/connection.spec.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,11 @@ describe("connection tests", function () {
213213

214214
client.on('error', function(err) {
215215
assert(/Redis connection in broken state: connection timeout.*?exceeded./.test(err.message));
216-
assert(Date.now() - time < connect_timeout + 25);
217-
assert(Date.now() - time >= connect_timeout - 3); // Timers sometimes trigger early (e.g. 1ms to early)
216+
// The code execution on windows is very slow at times
217+
var now = Date.now();
218+
assert(now - time < connect_timeout + 50, 'The real timeout time should be below ' + (connect_timeout + 50) + 'ms but is: ' + (now - time));
219+
// Timers sometimes trigger early (e.g. 1ms to early)
220+
assert(now - time >= connect_timeout - 3, 'The real timeout time should be above ' + connect_timeout + 'ms, but it is: ' + (now - time));
218221
done();
219222
});
220223
});
@@ -464,9 +467,9 @@ describe("connection tests", function () {
464467
};
465468
client.on("ready", function () {
466469
var rest = Date.now() - time;
467-
assert(rest >= 500);
470+
assert(rest >= 498, 'Rest should be equal or above 500 ms but is: ' + rest); // setTimeout might trigger early
468471
// Be on the safe side and accept 200ms above the original value
469-
assert(rest - 200 < 500);
472+
assert(rest - 200 < 500, 'Rest - 200 should be below 500 ms but is: ' + (rest - 200));
470473
assert(delayed);
471474
end();
472475
});
@@ -495,9 +498,9 @@ describe("connection tests", function () {
495498
};
496499
client.on("ready", function () {
497500
var rest = Date.now() - time;
498-
assert(rest >= 1000);
501+
assert(rest >= 998, '`rest` should be equal or above 1000 ms but is: ' + rest); // setTimeout might trigger early
499502
// Be on the safe side and accept 200ms above the original value
500-
assert(rest - 200 < 1000);
503+
assert(rest - 200 < 1000, '`rest` - 200 should be below 1000 ms but is: ' + (rest - 200));
501504
assert(delayed);
502505
end();
503506
});

test/node_redis.spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,11 @@ describe("The node_redis client", function () {
591591
return done();
592592
}
593593
});
594+
client.on('error', function (err) {
595+
// This is rare but it might be triggered.
596+
// So let's have a robust test
597+
assert.strictEqual(err.code, 'ECONNRESET');
598+
});
594599
});
595600
});
596601

0 commit comments

Comments
 (0)