-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathdomain-tests.js
58 lines (54 loc) · 1.62 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
54
55
56
57
58
var helper = require('./test-helper')
var async = require('async')
var testWithoutDomain = function(cb) {
test('no domain', function() {
assert(!process.domain)
helper.pg.connect(helper.config, assert.success(function(client, done) {
assert(!process.domain)
done()
cb()
}))
})
}
var testWithDomain = function(cb) {
test('with domain', function() {
assert(!process.domain)
var domain = require('domain').create()
domain.run(function() {
var startingDomain = process.domain
assert(startingDomain)
helper.pg.connect(helper.config, 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()
cb()
}))
}))
})
})
}
var testErrorWithDomain = function(cb) {
test('error on domain', function() {
var domain = require('domain').create()
domain.on('error', function() {
cb()
})
domain.run(function() {
helper.pg.connect(helper.config, assert.success(function(client, done) {
client.query('SELECT SLDKJFLSKDJF')
client.on('drain', done)
}))
})
})
}
async.series([
testWithoutDomain,
testWithDomain,
testErrorWithDomain
], function() {
helper.pg.end()
})