Merge pull request #354 from andreypopp/native-fix-domain

Preserve an active domain on I/O in native bindings
This commit is contained in:
Brian C 2013-05-20 15:16:17 -07:00
commit 1995601dda
3 changed files with 30 additions and 0 deletions

View File

@ -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;

View File

@ -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();
});
});
})

View File

@ -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();
});
});
})