From 5459773b902dd10fe0716bdc1c820558eeeb12a3 Mon Sep 17 00:00:00 2001 From: brianc Date: Thu, 3 Mar 2011 23:30:17 +0000 Subject: [PATCH 1/2] properly emit notice messages on client --- lib/client.js | 8 +++++--- test/integration/client/notice-tests.js | 11 +++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 test/integration/client/notice-tests.js diff --git a/lib/client.js b/lib/client.js index a8fa07b7..c7e613d0 100644 --- a/lib/client.js +++ b/lib/client.js @@ -23,9 +23,6 @@ var Client = function(config) { this.password = config.password || defaults.password; this.encoding = 'utf8'; var self = this; - this.connection.on('notify', function(msg) { - self.emit('notify', msg); - }) }; sys.inherits(Client, EventEmitter); @@ -111,6 +108,11 @@ p.connect = function() { self.activeQuery = null; } }); + + con.on('notice', function(msg) { + self.emit('notice', msg); + }) + }; p._pulseQueryQueue = function() { diff --git a/test/integration/client/notice-tests.js b/test/integration/client/notice-tests.js new file mode 100644 index 00000000..2aa0001c --- /dev/null +++ b/test/integration/client/notice-tests.js @@ -0,0 +1,11 @@ +var helper = require(__dirname + '/test-helper'); +test('emits notice message', function() { + var client = helper.client(); + + client.query('create temp table boom(id serial, size integer)'); + + assert.emits(client, 'notice', function(notice) { + assert.ok(notice != null); + client.end(); + }); +}) From 1cd1721f7f9a26c88a1a1dce0603664598aefa20 Mon Sep 17 00:00:00 2001 From: brianc Date: Fri, 4 Mar 2011 19:30:19 +0000 Subject: [PATCH 2/2] integration notification tests --- lib/client.js | 4 ++++ test/integration/client/notice-tests.js | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/client.js b/lib/client.js index c7e613d0..b6db53fb 100644 --- a/lib/client.js +++ b/lib/client.js @@ -85,6 +85,10 @@ p.connect = function() { } }); + con.on('notification', function(msg) { + self.emit('notification', msg); + }) + }); con.on('readyForQuery', function() { diff --git a/test/integration/client/notice-tests.js b/test/integration/client/notice-tests.js index 2aa0001c..b3c5f434 100644 --- a/test/integration/client/notice-tests.js +++ b/test/integration/client/notice-tests.js @@ -1,11 +1,26 @@ var helper = require(__dirname + '/test-helper'); test('emits notice message', function() { var client = helper.client(); - client.query('create temp table boom(id serial, size integer)'); - assert.emits(client, 'notice', function(notice) { assert.ok(notice != null); client.end(); }); }) + +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() { + client.query('NOTIFY boom'); + assert.emits(client, 'notification', function(msg) { + client.end() + }); + assert.emits(otherClient, 'notification', function(msg) { + otherClient.end(); + }); + })); + })); +}) +