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

Use connect_timeout also as the socket_timeout if explicitly provided

Fixes #587
Fixes #393
Closes #652
Closes #394
This commit is contained in:
Ruben Bridgewater
2015-10-29 13:49:01 +01:00
parent afc4989495
commit dc6fc9c113
4 changed files with 55 additions and 4 deletions

View File

@@ -125,6 +125,48 @@ describe("connection tests", function () {
describe("when not connected", function () {
it("emit an error after the socket timeout exceeded the connect_timeout time", function (done) {
var connect_timeout = 1000; // in ms
var client = redis.createClient({
parser: parser,
host: '1.2.3.4',
connect_timeout: connect_timeout
});
assert(client.stream._events.timeout);
assert.strictEqual(client.address, '1.2.3.4:6379');
var time = Date.now();
client.on("reconnecting", function (params) {
throw new Error('No reconnect, since no connection was ever established');
});
client.on('error', function(err) {
assert(/Redis connection in broken state: connection timeout.*?exceeded./.test(err.message));
assert(Date.now() - time < connect_timeout + 50);
done();
});
});
it("use the system socket timeout if the connect_timeout has not been provided", function () {
var client = redis.createClient({
parser: parser,
host: '1.2.3.4'
});
assert(client.stream._events.timeout === undefined);
});
it("clears the socket timeout after a connection has been established", function (done) {
var client = redis.createClient({
parser: parser,
connect_timeout: 1000
});
assert.strictEqual(client.stream._idleTimeout, 1000);
client.on('connect', function () {
assert.strictEqual(client.stream._idleTimeout, -1);
done();
});
});
it("connect with host and port provided in the options object", function (done) {
client = redis.createClient({
host: 'localhost',