-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathnotice-tests.js
56 lines (53 loc) · 1.69 KB
/
notice-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
'use strict'
var helper = require('./test-helper')
const suite = new helper.Suite()
suite.test('emits notify message', function (done) {
var client = helper.client()
client.query('LISTEN boom', assert.calls(function () {
var otherClient = helper.client()
var bothEmitted = -1
otherClient.query('LISTEN boom', assert.calls(function () {
assert.emits(client, 'notification', function (msg) {
// make sure PQfreemem doesn't invalidate string pointers
setTimeout(function () {
assert.equal(msg.channel, 'boom')
assert.ok(msg.payload == 'omg!' /* 9.x */ || msg.payload == '' /* 8.x */, 'expected blank payload or correct payload but got ' + msg.message)
client.end(++bothEmitted ? done : undefined)
}, 100)
})
assert.emits(otherClient, 'notification', function (msg) {
assert.equal(msg.channel, 'boom')
otherClient.end(++bothEmitted ? done : undefined)
})
client.query("NOTIFY boom, 'omg!'", function (err, q) {
if (err) {
// notify not supported with payload on 8.x
client.query('NOTIFY boom')
}
})
}))
}))
})
// this test fails on travis due to their config
suite.test('emits notice message', false, function (done) {
if (helper.args.native) {
console.error('need to get notice message working on native')
return done()
}
// TODO this doesn't work on all versions of postgres
var client = helper.client()
const text = `
DO language plpgsql $$
BEGIN
RAISE NOTICE 'hello, world!';
END
$$;
`
client.query(text, () => {
client.end()
})
assert.emits(client, 'notice', function (notice) {
assert.ok(notice != null)
done()
})
})