2010-11-01 03:49:49 +08:00
|
|
|
var helper = require(__dirname + '/test-helper');
|
2011-08-29 15:35:08 +08:00
|
|
|
var Connection = require(__dirname + '/../../../lib/connection');
|
2010-11-01 03:49:49 +08:00
|
|
|
test("connection emits stream errors", function() {
|
2013-03-29 22:38:49 +08:00
|
|
|
var con = new Connection({stream: new MemoryStream()});
|
2010-11-01 03:49:49 +08:00
|
|
|
assert.emits(con, 'error', function(err) {
|
2011-09-22 03:34:02 +08:00
|
|
|
assert.equal(err.message, "OMG!");
|
2010-11-01 03:49:49 +08:00
|
|
|
});
|
|
|
|
con.connect();
|
2011-09-22 03:34:02 +08:00
|
|
|
con.stream.emit('error', new Error("OMG!"));
|
2010-11-01 03:49:49 +08:00
|
|
|
});
|
2013-03-29 22:38:49 +08:00
|
|
|
|
|
|
|
test('connection emits ECONNRESET errors during normal operation', function() {
|
|
|
|
var con = new Connection({stream: new MemoryStream()});
|
|
|
|
con.connect();
|
|
|
|
assert.emits(con, 'error', function(err) {
|
|
|
|
assert.equal(err.code, 'ECONNRESET');
|
|
|
|
});
|
|
|
|
var e = new Error('Connection Reset');
|
|
|
|
e.code = 'ECONNRESET';
|
|
|
|
con.stream.emit('error', e);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('connection does not emit ECONNRESET errors during disconnect', function() {
|
|
|
|
var con = new Connection({stream: new MemoryStream()});
|
|
|
|
con.connect();
|
|
|
|
var e = new Error('Connection Reset');
|
|
|
|
e.code = 'ECONNRESET';
|
|
|
|
con.end();
|
|
|
|
con.stream.emit('error', e);
|
|
|
|
});
|