Skip to content

Commit 1995601

Browse files
committed
Merge pull request brianc#354 from andreypopp/native-fix-domain
Preserve an active domain on I/O in native bindings
2 parents 3bfc8e9 + 4458e69 commit 1995601

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

lib/native/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ Connection.prototype.sendCopyFail = function(msg) {
155155
var clientBuilder = function(config) {
156156
config = config || {};
157157
var connection = new Connection();
158+
EventEmitter.call(connection);
158159
connection._queryQueue = [];
159160
connection._namedQueries = {};
160161
connection._activeQuery = null;

test/native/callback-api-tests.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var domain = require('domain');
12
var helper = require(__dirname + "/../test-helper");
23
var Client = require(__dirname + "/../../lib/native");
34

@@ -14,3 +15,17 @@ test('fires callback with results', function() {
1415
}))
1516
}));
1617
})
18+
19+
test('preserves domain', function() {
20+
var dom = domain.create();
21+
22+
dom.run(function() {
23+
var client = new Client(helper.config);
24+
assert.ok(dom === require('domain').active, 'domain is active');
25+
client.connect()
26+
client.query('select 1', function() {
27+
assert.ok(dom === require('domain').active, 'domain is still active');
28+
client.end();
29+
});
30+
});
31+
})

test/native/connection-tests.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var helper = require(__dirname + "/../test-helper");
22
var Client = require(__dirname + "/../../lib/native");
3+
var domain = require('domain');
34

45
test('connecting with wrong parameters', function() {
56
var con = new Client("user=asldfkj hostaddr=127.0.0.1 port=5432 dbname=asldkfj");
@@ -20,3 +21,16 @@ test('connects', function() {
2021
})
2122
})
2223
})
24+
25+
test('preserves domain', function() {
26+
var dom = domain.create();
27+
28+
dom.run(function() {
29+
var con = new Client(helper.config);
30+
assert.ok(dom === require('domain').active, 'domain is active');
31+
con.connect(function() {
32+
assert.ok(dom === require('domain').active, 'domain is still active');
33+
con.end();
34+
});
35+
});
36+
})

0 commit comments

Comments
 (0)