forked from mysqljs/mysql
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bind underlying connections in pool to same domain as pool
fixes mysqljs#1242
- Loading branch information
1 parent
6aeaed6
commit bf958d0
Showing
4 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
var after = require('after'); | ||
var assert = require('assert'); | ||
var common = require('../../common'); | ||
var domain = null; | ||
|
||
try { | ||
domain = require('domain'); | ||
} catch (e) { | ||
common.skipTest('node ' + process.version + ' does not support domains'); | ||
} | ||
|
||
var d0 = domain.create(); | ||
var d1 = domain.create(); | ||
|
||
var server = common.createFakeServer(); | ||
|
||
var pool = null; | ||
var done = after(2, function () { | ||
pool.end(function (err) { | ||
assert.ifError(err); | ||
server.destroy(); | ||
}); | ||
}); | ||
|
||
server.listen(common.fakeServerPort, function (err) { | ||
assert.ifError(err); | ||
|
||
var released = false; | ||
var timer = setInterval(function () { | ||
if (!released) return; | ||
clearInterval(timer); | ||
|
||
assert.ok(!domain.active, 'no current domain'); | ||
pool.getConnection(function (err, conn) { | ||
assert.ifError(err); | ||
assert.equal(domain.active, d0, 'current domain is d0'); | ||
assert.equal(conn.domain, d0, 'connection domain is d0'); | ||
conn.release(); | ||
done(); | ||
}); | ||
}, 200); | ||
|
||
d0.run(function () { | ||
pool = common.createPool({port: common.fakeServerPort, connectionLimit: 1}); | ||
assert.equal(pool.domain, d0, 'pool belongs to d0'); | ||
|
||
d1.run(function () { | ||
pool.getConnection(function (err, conn) { | ||
assert.ifError(err); | ||
assert.equal(domain.active, d1, 'current domain is d1'); | ||
assert.equal(conn.domain, d0, 'connection domain is d0'); | ||
conn.release(); | ||
released = true; | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
var after = require('after'); | ||
var assert = require('assert'); | ||
var common = require('../../common'); | ||
var domain = null; | ||
|
||
try { | ||
domain = require('domain'); | ||
} catch (e) { | ||
common.skipTest('node ' + process.version + ' does not support domains'); | ||
} | ||
|
||
var d0 = domain.create(); | ||
|
||
var server = common.createFakeServer(); | ||
|
||
var pool = null; | ||
var done = after(2, function () { | ||
pool.end(function (err) { | ||
assert.ifError(err); | ||
server.destroy(); | ||
}); | ||
}); | ||
|
||
server.listen(common.fakeServerPort, function (err) { | ||
assert.ifError(err); | ||
|
||
var released = false; | ||
var timer = setInterval(function () { | ||
if (!released) return; | ||
clearInterval(timer); | ||
|
||
assert.ok(!domain.active, 'no current domain'); | ||
pool.getConnection(function (err, conn) { | ||
assert.ifError(err); | ||
assert.ok(!domain.active, 'no current domain'); | ||
assert.equal(conn.domain, null, 'connection is not bound to domain'); | ||
conn.release(); | ||
done(); | ||
}); | ||
}, 200); | ||
|
||
pool = common.createPool({port: common.fakeServerPort, connectionLimit: 1}); | ||
assert.equal(pool.domain, null, 'pool is not bound to domain'); | ||
|
||
d0.run(function () { | ||
pool.getConnection(function (err, conn) { | ||
assert.ifError(err); | ||
assert.equal(domain.active, d0, 'current domain is d0'); | ||
assert.equal(conn.domain, null, 'connection is not bound to domain'); | ||
conn.release(); | ||
released = true; | ||
done(); | ||
}); | ||
}); | ||
}); |