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

Remove listener if not needed anymore and alawys end a client after a test

This commit is contained in:
Ruben Bridgewater
2015-10-29 15:04:47 +01:00
parent dc6fc9c113
commit 7718e219e9
3 changed files with 19 additions and 10 deletions

View File

@@ -115,7 +115,8 @@ RedisClient.prototype.install_stream_listeners = function() {
}); });
} }
this.stream.on('connect', function () { this.stream.once('connect', function () {
this.removeAllListeners("timeout");
self.on_connect(); self.on_connect();
}); });

View File

@@ -20,6 +20,9 @@ describe("client authentication", function () {
var auth = 'porkchopsandwiches'; var auth = 'porkchopsandwiches';
var client = null; var client = null;
beforeEach(function () {
client = null;
});
afterEach(function () { afterEach(function () {
client.end(); client.end();
}); });

View File

@@ -13,10 +13,11 @@ describe("connection tests", function () {
var client; var client;
beforeEach(function () {
client = null;
});
afterEach(function () { afterEach(function () {
if (client) { client.end();
client.end();
}
}); });
describe("on lost connection", function () { describe("on lost connection", function () {
@@ -127,13 +128,13 @@ describe("connection tests", function () {
it("emit an error after the socket timeout exceeded the connect_timeout time", function (done) { it("emit an error after the socket timeout exceeded the connect_timeout time", function (done) {
var connect_timeout = 1000; // in ms var connect_timeout = 1000; // in ms
var client = redis.createClient({ client = redis.createClient({
parser: parser, parser: parser,
host: '1.2.3.4', host: '192.168.74.167',
connect_timeout: connect_timeout connect_timeout: connect_timeout
}); });
assert(client.stream._events.timeout); assert(client.stream._events.timeout);
assert.strictEqual(client.address, '1.2.3.4:6379'); assert.strictEqual(client.address, '192.168.74.167:6379');
var time = Date.now(); var time = Date.now();
client.on("reconnecting", function (params) { client.on("reconnecting", function (params) {
@@ -148,21 +149,22 @@ describe("connection tests", function () {
}); });
it("use the system socket timeout if the connect_timeout has not been provided", function () { it("use the system socket timeout if the connect_timeout has not been provided", function () {
var client = redis.createClient({ client = redis.createClient({
parser: parser, parser: parser,
host: '1.2.3.4' host: '192.168.74.167'
}); });
assert(client.stream._events.timeout === undefined); assert(client.stream._events.timeout === undefined);
}); });
it("clears the socket timeout after a connection has been established", function (done) { it("clears the socket timeout after a connection has been established", function (done) {
var client = redis.createClient({ client = redis.createClient({
parser: parser, parser: parser,
connect_timeout: 1000 connect_timeout: 1000
}); });
assert.strictEqual(client.stream._idleTimeout, 1000); assert.strictEqual(client.stream._idleTimeout, 1000);
client.on('connect', function () { client.on('connect', function () {
assert.strictEqual(client.stream._idleTimeout, -1); assert.strictEqual(client.stream._idleTimeout, -1);
assert(client.stream._events.timeout === undefined);
done(); done();
}); });
}); });
@@ -255,6 +257,9 @@ describe("connection tests", function () {
}); });
it("throws on strange connection info", function () { it("throws on strange connection info", function () {
client = {
end: function() {}
};
try { try {
redis.createClient(true); redis.createClient(true);
throw new Error('failed'); throw new Error('failed');