Skip to content

Commit 7718e21

Browse files
author
Ruben Bridgewater
committed
Remove listener if not needed anymore and alawys end a client after a test
1 parent dc6fc9c commit 7718e21

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ RedisClient.prototype.install_stream_listeners = function() {
115115
});
116116
}
117117

118-
this.stream.on('connect', function () {
118+
this.stream.once('connect', function () {
119+
this.removeAllListeners("timeout");
119120
self.on_connect();
120121
});
121122

test/auth.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ describe("client authentication", function () {
2020
var auth = 'porkchopsandwiches';
2121
var client = null;
2222

23+
beforeEach(function () {
24+
client = null;
25+
});
2326
afterEach(function () {
2427
client.end();
2528
});

test/connection.spec.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ describe("connection tests", function () {
1313

1414
var client;
1515

16+
beforeEach(function () {
17+
client = null;
18+
});
1619
afterEach(function () {
17-
if (client) {
18-
client.end();
19-
}
20+
client.end();
2021
});
2122

2223
describe("on lost connection", function () {
@@ -127,13 +128,13 @@ describe("connection tests", function () {
127128

128129
it("emit an error after the socket timeout exceeded the connect_timeout time", function (done) {
129130
var connect_timeout = 1000; // in ms
130-
var client = redis.createClient({
131+
client = redis.createClient({
131132
parser: parser,
132-
host: '1.2.3.4',
133+
host: '192.168.74.167',
133134
connect_timeout: connect_timeout
134135
});
135136
assert(client.stream._events.timeout);
136-
assert.strictEqual(client.address, '1.2.3.4:6379');
137+
assert.strictEqual(client.address, '192.168.74.167:6379');
137138
var time = Date.now();
138139

139140
client.on("reconnecting", function (params) {
@@ -148,21 +149,22 @@ describe("connection tests", function () {
148149
});
149150

150151
it("use the system socket timeout if the connect_timeout has not been provided", function () {
151-
var client = redis.createClient({
152+
client = redis.createClient({
152153
parser: parser,
153-
host: '1.2.3.4'
154+
host: '192.168.74.167'
154155
});
155156
assert(client.stream._events.timeout === undefined);
156157
});
157158

158159
it("clears the socket timeout after a connection has been established", function (done) {
159-
var client = redis.createClient({
160+
client = redis.createClient({
160161
parser: parser,
161162
connect_timeout: 1000
162163
});
163164
assert.strictEqual(client.stream._idleTimeout, 1000);
164165
client.on('connect', function () {
165166
assert.strictEqual(client.stream._idleTimeout, -1);
167+
assert(client.stream._events.timeout === undefined);
166168
done();
167169
});
168170
});
@@ -255,6 +257,9 @@ describe("connection tests", function () {
255257
});
256258

257259
it("throws on strange connection info", function () {
260+
client = {
261+
end: function() {}
262+
};
258263
try {
259264
redis.createClient(true);
260265
throw new Error('failed');

0 commit comments

Comments
 (0)