|
1 | 1 | 'use strict' |
2 | 2 | var helper = require(__dirname + '/test-helper') |
3 | 3 | var Connection = require(__dirname + '/../../../lib/connection') |
4 | | -test('connection emits stream errors', function () { |
| 4 | +var net = require('net') |
| 5 | + |
| 6 | +const suite = new helper.Suite() |
| 7 | + |
| 8 | +suite.test('connection emits stream errors', function (done) { |
5 | 9 | var con = new Connection({stream: new MemoryStream()}) |
6 | 10 | assert.emits(con, 'error', function (err) { |
7 | 11 | assert.equal(err.message, 'OMG!') |
| 12 | + done() |
8 | 13 | }) |
9 | 14 | con.connect() |
10 | 15 | con.stream.emit('error', new Error('OMG!')) |
11 | 16 | }) |
12 | 17 |
|
13 | | -test('connection emits ECONNRESET errors during normal operation', function () { |
| 18 | +suite.test('connection emits ECONNRESET errors during normal operation', function (done) { |
14 | 19 | var con = new Connection({stream: new MemoryStream()}) |
15 | 20 | con.connect() |
16 | 21 | assert.emits(con, 'error', function (err) { |
17 | 22 | assert.equal(err.code, 'ECONNRESET') |
| 23 | + done() |
18 | 24 | }) |
19 | 25 | var e = new Error('Connection Reset') |
20 | 26 | e.code = 'ECONNRESET' |
21 | 27 | con.stream.emit('error', e) |
22 | 28 | }) |
23 | 29 |
|
24 | | -test('connection does not emit ECONNRESET errors during disconnect', function () { |
| 30 | +suite.test('connection does not emit ECONNRESET errors during disconnect', function (done) { |
25 | 31 | var con = new Connection({stream: new MemoryStream()}) |
26 | 32 | con.connect() |
27 | 33 | var e = new Error('Connection Reset') |
28 | 34 | e.code = 'ECONNRESET' |
29 | 35 | con.end() |
30 | 36 | con.stream.emit('error', e) |
| 37 | + done() |
| 38 | +}) |
| 39 | + |
| 40 | + |
| 41 | +suite.test('connection does not emit ECONNRESET errors during disconnect also when using SSL', function (done) { |
| 42 | + // our fake postgres server, which just responds with 'S' to start SSL |
| 43 | + var socket |
| 44 | + var server = net.createServer(function (c) { |
| 45 | + socket = c |
| 46 | + c.once('data', function (data) { |
| 47 | + c.write(new Buffer('S', 'utf8')) |
| 48 | + }) |
| 49 | + }) |
| 50 | + |
| 51 | + server.listen(7778, function () { |
| 52 | + var con = new Connection({ssl: true}) |
| 53 | + con.connect(7778, 'localhost') |
| 54 | + assert.emits(con, 'sslconnect', function () { |
| 55 | + con.end() |
| 56 | + socket.destroy() |
| 57 | + server.close() |
| 58 | + done() |
| 59 | + }) |
| 60 | + con.requestSsl() |
| 61 | + }) |
31 | 62 | }) |
0 commit comments