-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathdomain-tests.js
53 lines (48 loc) · 1.5 KB
/
domain-tests.js
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
'use strict'
var async = require('async')
var helper = require('./test-helper')
var Query = helper.pg.Query
var suite = new helper.Suite()
const Pool = helper.pg.Pool
suite.test('no domain', function (cb) {
assert(!process.domain)
const pool = new Pool()
pool.connect(assert.success(function (client, done) {
assert(!process.domain)
done()
pool.end(cb)
}))
})
suite.test('with domain', function (cb) {
assert(!process.domain)
const pool = new Pool()
var domain = require('domain').create()
domain.run(function () {
var startingDomain = process.domain
assert(startingDomain)
pool.connect(assert.success(function (client, done) {
assert(process.domain, 'no domain exists in connect callback')
assert.equal(startingDomain, process.domain, 'domain was lost when checking out a client')
var query = client.query('SELECT NOW()', assert.success(function () {
assert(process.domain, 'no domain exists in query callback')
assert.equal(startingDomain, process.domain, 'domain was lost when checking out a client')
done(true)
process.domain.exit()
pool.end(cb)
}))
}))
})
})
suite.test('error on domain', function (cb) {
var domain = require('domain').create()
const pool = new Pool()
domain.on('error', function () {
pool.end(cb)
})
domain.run(function () {
pool.connect(assert.success(function (client, done) {
client.query(new Query('SELECT SLDKJFLSKDJF'))
client.on('drain', done)
}))
})
})