GH-55 Client emits connect event multiple times

This commit is contained in:
Mark Cavage 2012-01-30 08:45:01 -08:00
parent 950b11695f
commit b47b208e5d
2 changed files with 25 additions and 3 deletions

View File

@ -198,11 +198,9 @@ Client.prototype.connect = function(callback) {
self.connection.end(); self.connection.end();
} }
self.emit('connect');
return callback(); return callback();
}); });
self.emit('connect');
return callback(); return callback();
}); });
@ -854,7 +852,7 @@ Client.prototype._newConnection = function() {
c.ldap.connected = true; c.ldap.connected = true;
c.ldap.id += c.fd ? (':' + c.fd) : ''; c.ldap.id += c.fd ? (':' + c.fd) : '';
c.emit('connect', true); c.emit('connect', c.ldap.id);
}); });
c.setKeepAlive = function(enable, delay) { c.setKeepAlive = function(enable, delay) {
return c.socket.setKeepAlive(enable, delay); return c.socket.setKeepAlive(enable, delay);

View File

@ -52,6 +52,10 @@ test('setup', function(t) {
t.end(); t.end();
}); });
server.bind('cn=root', function(req, res, next) {
res.end();
return next();
});
server.search(SUFFIX, function(req, res, next) { server.search(SUFFIX, function(req, res, next) {
var entry = { var entry = {
dn: 'cn=foo, ' + SUFFIX, dn: 'cn=foo, ' + SUFFIX,
@ -106,6 +110,26 @@ test('GH-49 Client errors on bad attributes', function(t) {
}); });
test('GH-55 Client emits connect multiple times', function(t) {
var c = ldap.createClient({
socketPath: SOCKET
});
var count = 0;
c.on('connect', function(socket) {
t.ok(socket);
count++;
});
c.bind('cn=root', 'secret', function(err, res) {
t.ifError(err);
c.unbind(function() {
t.equal(count, 1);
t.end();
});
});
});
test('shutdown', function(t) { test('shutdown', function(t) {
client.unbind(function() { client.unbind(function() {
server.on('close', function() { server.on('close', function() {