diff --git a/lib/native/index.js b/lib/native/index.js index 69f38850..d6dd4b22 100644 --- a/lib/native/index.js +++ b/lib/native/index.js @@ -155,6 +155,7 @@ Connection.prototype.sendCopyFail = function(msg) { var clientBuilder = function(config) { config = config || {}; var connection = new Connection(); + EventEmitter.call(connection); connection._queryQueue = []; connection._namedQueries = {}; connection._activeQuery = null; diff --git a/test/native/callback-api-tests.js b/test/native/callback-api-tests.js index 45006682..0b713573 100644 --- a/test/native/callback-api-tests.js +++ b/test/native/callback-api-tests.js @@ -1,3 +1,4 @@ +var domain = require('domain'); var helper = require(__dirname + "/../test-helper"); var Client = require(__dirname + "/../../lib/native"); @@ -14,3 +15,17 @@ test('fires callback with results', function() { })) })); }) + +test('preserves domain', function() { + var dom = domain.create(); + + dom.run(function() { + var client = new Client(helper.config); + assert.ok(dom === require('domain').active, 'domain is active'); + client.connect() + client.query('select 1', function() { + assert.ok(dom === require('domain').active, 'domain is still active'); + client.end(); + }); + }); +}) diff --git a/test/native/connection-tests.js b/test/native/connection-tests.js index 1cb0ed88..be84be6e 100644 --- a/test/native/connection-tests.js +++ b/test/native/connection-tests.js @@ -1,5 +1,6 @@ var helper = require(__dirname + "/../test-helper"); var Client = require(__dirname + "/../../lib/native"); +var domain = require('domain'); test('connecting with wrong parameters', function() { var con = new Client("user=asldfkj hostaddr=127.0.0.1 port=5432 dbname=asldkfj"); @@ -20,3 +21,16 @@ test('connects', function() { }) }) }) + +test('preserves domain', function() { + var dom = domain.create(); + + dom.run(function() { + var con = new Client(helper.config); + assert.ok(dom === require('domain').active, 'domain is active'); + con.connect(function() { + assert.ok(dom === require('domain').active, 'domain is still active'); + con.end(); + }); + }); +})