2011-03-04 07:30:17 +08:00
|
|
|
var helper = require(__dirname + '/test-helper');
|
|
|
|
test('emits notice message', function() {
|
2012-08-07 21:44:41 +08:00
|
|
|
//TODO this doesn't work on all versions of postgres
|
|
|
|
return false;
|
2011-03-04 07:30:17 +08:00
|
|
|
var client = helper.client();
|
|
|
|
client.query('create temp table boom(id serial, size integer)');
|
|
|
|
assert.emits(client, 'notice', function(notice) {
|
|
|
|
assert.ok(notice != null);
|
2011-03-05 04:04:59 +08:00
|
|
|
//TODO ending connection after notice generates weird errors
|
|
|
|
process.nextTick(function() {
|
|
|
|
client.end();
|
|
|
|
})
|
2011-03-04 07:30:17 +08:00
|
|
|
});
|
|
|
|
})
|
2011-03-05 03:30:19 +08:00
|
|
|
|
|
|
|
test('emits notify message', function() {
|
|
|
|
var client = helper.client();
|
|
|
|
client.query('LISTEN boom', assert.calls(function() {
|
|
|
|
var otherClient = helper.client();
|
|
|
|
otherClient.query('LISTEN boom', assert.calls(function() {
|
2011-04-15 12:20:15 +08:00
|
|
|
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()
|
2011-05-20 09:46:27 +08:00
|
|
|
}, 100)
|
2011-04-15 11:53:44 +08:00
|
|
|
|
2011-04-15 12:20:15 +08:00
|
|
|
});
|
|
|
|
assert.emits(otherClient, 'notification', function(msg) {
|
|
|
|
assert.equal(msg.channel, 'boom');
|
|
|
|
otherClient.end();
|
|
|
|
});
|
2011-04-15 12:11:36 +08:00
|
|
|
|
|
|
|
client.query("NOTIFY boom, 'omg!'", function(err, q) {
|
|
|
|
if(err) {
|
|
|
|
//notify not supported with payload on 8.x
|
|
|
|
client.query("NOTIFY boom")
|
2011-04-15 12:20:15 +08:00
|
|
|
}
|
2011-03-05 03:30:19 +08:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
})
|
|
|
|
|