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