Commit 5a3b9240 authored by Arnout Kazemier's avatar Arnout Kazemier

Merge pull request #136 from ianshward/fix-timeout-test

error on timeout now handled by jackpot
parents 658218e2 c0c56c73
......@@ -155,13 +155,8 @@ Client.config = {
, idleTimeout = function() {
Manager.remove(this);
}
, connectTimeout = function() {
memcached.connectionIssue('Stream connect timeout', S);
Manager.remove(this);
memcached.makeCallback(callback, new Error('Stream connect timeout'));
}
, streamError = function() {
memcached.connectionIssue('Stream error', S);
, streamError = function(e) {
memcached.connectionIssue(e.toString(), S);
Manager.remove(this);
};
......@@ -183,13 +178,14 @@ Client.config = {
Manager.remove(this);
}
, data: curry(memcached, privates.buffer, S)
, timeout: connectTimeout
, error: streamError
, connect: function streamConnect() {
// Remove connection timeout listener
this.setTimeout(0, connectTimeout);
// Close idle connections
// Jackpot handles any pre-connect timeouts by calling back
// with the error object.
this.setTimeout(this.memcached.idle, idleTimeout);
// Jackpot handles any pre-connect errors, but does not handle errors
// once a connection has been made, nor does Jackpot handle releasing
// connections if an error occurs post-connect
this.on('error', streamError);
}
, end: S.end
});
......@@ -307,11 +303,21 @@ Client.config = {
}
// check for issues
if (error) return query.callback && memcached.makeCallback(query.callback,error);
if (!S) return query.callback && memcached.makeCallback(query.callback,new Error('Connect did not give a server'));
if (error) {
memcached.connectionIssue(error.toString(), S);
return query.callback && memcached.makeCallback(query.callback,error);
}
if (!S) {
var message = 'Connect did not give a server';
memcached.connectionIssue(message);
return query.callback && memcached.makeCallback(query.callback,new Error(message));
}
if (S.readyState !== 'open') {
return query.callback && memcached.makeCallback(query.callback,new Error('Connection readyState is set to ' + S.readySate));
var message = 'Connection readyState is set to ' + S.readyState;
memcached.connectionIssue(message, S);
return query.callback && memcached.makeCallback(query.callback,new Error(message));
}
// used for request timing
......
......@@ -154,6 +154,7 @@ describe('Memcached connections', function () {
// First request will mark server failed
memcached.get('idontcare', function(err) {
assert.throws(function() { throw err }, /connect ECONNREFUSED/);
// Wait 10ms, server should be back online
setTimeout(function() {
// Second request will mark server dead
memcached.get('idontcare', function(err) {
......@@ -171,10 +172,10 @@ describe('Memcached connections', function () {
memcached.end();
done();
});
}, 110);
}, 150);
});
});
},10); // Make sure `retry`, which is immediate, has passed
},10);
});
});
it('should return error on connection timeout', function(done) {
......@@ -187,7 +188,7 @@ describe('Memcached connections', function () {
failures: 0 });
memcached.get('idontcare', function(err) {
assert.throws(function() { throw err }, /Stream connect timeout/);
assert.throws(function() { throw err }, /Timed out while trying to establish connection/);
memcached.end();
done();
});
......@@ -208,4 +209,25 @@ describe('Memcached connections', function () {
}, 100);
});
});
it('should remove server if error occurs after connection established', function(done) {
var memcached = new Memcached(common.servers.single, {
poolSize: 1,
retries: 0,
timeout: 1000,
idle: 5000,
failures: 0 });
// Should work fine
memcached.get('idontcare', function(err) {
assert.ifError(err);
// Fake an error on the connected socket which should mark server failed
var S = memcached.connections[common.servers.single].pool.pop();
S.emit('error', new Error('Dummy error'));
memcached.get('idontcare', function(err) {
assert.throws(function() { throw err; }, /Server not available/);
done();
});
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment