Cease reconnection when client.destroy is called

This commit is contained in:
Patrick Mooney 2014-06-24 05:33:19 -05:00
parent 72bfb9b0f7
commit 3b101a7b2f
2 changed files with 33 additions and 0 deletions

View File

@ -686,6 +686,7 @@ Client.prototype.destroy = function destroy() {
});
}
this.unbind();
this.emit('destroy');
};
@ -919,6 +920,10 @@ Client.prototype._connect = function _connect() {
}
this.connecting = true;
retry.start();
// Abbord reconnection attemps if client is destroyed
this.on('destroy', function () {
retry.abort();
});
};
/**

View File

@ -618,6 +618,34 @@ test('idle timeout', function (t) {
});
test('abort reconnect', function (t) {
var abortClient = ldap.createClient({
connectTimeout: parseInt(process.env.LDAP_CONNECT_TIMEOUT || 0, 10),
socketPath: '/dev/null',
reconnect: {},
log: new Logger({
name: 'ldapjs_unit_test',
stream: process.stderr,
level: (process.env.LOG_LEVEL || 'info'),
serializers: Logger.stdSerializers,
src: true
})
});
var retryCount = 0;
abortClient.on('connectError', function () {
++retryCount;
});
abortClient.once('connectError', function () {
t.ok(true);
abortClient.once('destroy', function () {
t.ok(retryCount < 3);
t.end();
});
abortClient.destroy();
});
});
test('abandon (GH-27)', function (t) {
client.abandon(401876543, function (err) {
t.ifError(err);