forked from mongodb/node-mongodb-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make callbacks to be executed in right domain
When command is executed through non executed commands queue, callbacks are executed in wrong domain. Fix this.
- Loading branch information
Anton Kotenko
committed
Jun 12, 2014
1 parent
4e39078
commit 66f8987
Showing
3 changed files
with
135 additions
and
2 deletions.
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,131 @@ | ||
/** | ||
* @ignore | ||
*/ | ||
exports.shouldStayInCorrectDomainForReadCommand = function(configuration, test) { | ||
var Domain; | ||
|
||
try { | ||
Domain = require('domain'); | ||
} catch (e) { | ||
//Old node versions. Nothing to test | ||
test.done(); | ||
return; | ||
} | ||
|
||
var domainInstance = Domain.create(); | ||
var client = configuration.newDbInstance({w: 0}, {poolSize: 1, auto_reconnect: true}); | ||
|
||
client.open(function(err, client) { | ||
test.ok(!err); | ||
var collection = client.collection('test'); | ||
domainInstance.run(function() { | ||
collection.count({}, function(err) { | ||
test.ok(!err); | ||
test.ok(domainInstance === process.domain); | ||
test.done(); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* @ignore | ||
*/ | ||
exports.shouldStayInCorrectDomainForWriteCommand = function(configuration, test) { | ||
var Domain; | ||
|
||
try { | ||
Domain = require('domain'); | ||
} catch (e) { | ||
//Old node versions. Nothing to test | ||
test.done(); | ||
return; | ||
} | ||
|
||
var domainInstance = Domain.create(); | ||
var client = configuration.newDbInstance({w: 1}, {poolSize: 1, auto_reconnect: true}); | ||
|
||
client.open(function(err, client) { | ||
test.ok(!err); | ||
var collection = client.collection('test'); | ||
domainInstance.run(function() { | ||
collection.insert({field: 123}, function(err) { | ||
test.ok(!err); | ||
test.ok(domainInstance === process.domain); | ||
test.done(); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
|
||
/** | ||
* @ignore | ||
*/ | ||
exports.shouldStayInCorrectDomainForQueuedReadCommand = function(configuration, test) { | ||
var Domain; | ||
|
||
try { | ||
Domain = require('domain'); | ||
} catch (e) { | ||
//Old node versions. Nothing to test | ||
test.done(); | ||
return; | ||
} | ||
|
||
var domainInstance = Domain.create(); | ||
var client = configuration.newDbInstance({w: 0}, {poolSize: 1, auto_reconnect: true}); | ||
|
||
client.open(function(err, client) { | ||
var connection = client.serverConfig.connectionPool.openConnections[0]; | ||
var collection = client.collection('test'); | ||
|
||
//imitate connection error, to make commands queued into | ||
//commandsStore | ||
connection.emit('error', {err: 'fake disconnect'}, connection); | ||
|
||
domainInstance.run(function() { | ||
collection.count({}, function(err) { | ||
test.ok(!err); | ||
test.ok(process.domain === domainInstance); | ||
test.done(); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* @ignore | ||
*/ | ||
exports.shouldStayInCorrectDomainForQueuedWriteCommand = function(configuration, test) { | ||
var Domain; | ||
|
||
try { | ||
Domain = require('domain'); | ||
} catch (e) { | ||
//Old node versions. Nothing to test | ||
test.done(); | ||
return; | ||
} | ||
|
||
var domainInstance = Domain.create(); | ||
var client = configuration.newDbInstance({w: 1}, {poolSize: 1, auto_reconnect: true}); | ||
|
||
client.open(function(err, client) { | ||
test.ok(!err); | ||
var connection = client.serverConfig.connectionPool.openConnections[0]; | ||
var collection = client.collection('test'); | ||
|
||
//imitate connection error, to make commands queued into | ||
//commandsStore | ||
connection.emit('error', {err: 'fake disconnect'}, connection); | ||
|
||
domainInstance.run(function() { | ||
collection.insert({field: 123}, function(err) { | ||
test.ok(!err); | ||
test.ok(process.domain === domainInstance); | ||
test.done(); | ||
}); | ||
}); | ||
}); | ||
} |