Commit 6e8d12f0 authored by Phillip Kovalev's avatar Phillip Kovalev

add connection timeout test (option "idle")

parent dbd98f12
......@@ -8,6 +8,7 @@
var assert = require('assert')
, fs = require('fs')
, net = require('net')
, common = require('./common')
, Memcached = require('../');
......@@ -73,4 +74,53 @@ describe('Memcached connections', function () {
});
});
});
it('should fire `failure` event when server removed and has no fallbacks', function(done) {
var connectionAttempOk = false
, mockSocket = null
, mock = net.createServer(function(socket) {
mockSocket = socket;
connectionAttempOk = true;
})
, memcached = new Memcached(['127.0.0.1:11219'], {
timeout: 3000,
idle: 1000,
retries: 0,
remove: true
})
, emittedErrors = [];
[
'issue',
'remove',
'reconnecting',
'reconnected',
'failure'
].forEach(function(event) {
memcached.on(event, function() {
if (emittedErrors[event]) {
++emittedErrors[event];
} else {
emittedErrors[event] = 1;
}
});
});
mock.listen(11219, function() {
memcached.get('y', function(err) {
var events = Object.keys(emittedErrors);
// memcached instance must emit `remove` and `failure` events
assert.strictEqual(events.length, 2);
assert.ok(~events.indexOf('remove'));
assert.ok(~events.indexOf('failure'));
assert.ok(connectionAttempOk);
assert.strictEqual(err.message, 'Connection timeout');
memcached.end();
mockSocket.destroy();
mock.close();
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