Skip to content

Commit 0b49170

Browse files
committed
Added missing domains tests
1 parent 6e324a0 commit 0b49170

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed

test/functional/domain_tests.js

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
"use strict";
2+
3+
/**
4+
* @ignore
5+
*/
6+
exports.shouldStayInCorrectDomainForReadCommand = {
7+
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
8+
9+
// The actual test we wish to run
10+
test: function(configuration, test) {
11+
var Domain = require('domain');
12+
var domainInstance = Domain.create();
13+
var client = configuration.newDbInstance({w: 0}, {poolSize: 1, auto_reconnect: true, domainsEnabled:true});
14+
15+
client.open(function(err, client) {
16+
test.ok(!err);
17+
var collection = client.collection('test');
18+
domainInstance.run(function() {
19+
collection.count({}, function(err) {
20+
test.ok(!err);
21+
test.ok(domainInstance === process.domain);
22+
domainInstance.exit();
23+
domainInstance.dispose();
24+
client.close();
25+
test.done();
26+
});
27+
});
28+
});
29+
}
30+
}
31+
32+
/**
33+
* @ignore
34+
*/
35+
exports.shouldStayInCorrectDomainForReadCommandUsingMongoClient = {
36+
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
37+
38+
// The actual test we wish to run
39+
test: function(configuration, test) {
40+
var MongoClient = configuration.require.MongoClient;
41+
var Domain = require('domain');
42+
var domainInstance = Domain.create();
43+
44+
MongoClient.connect(configuration.url(), {
45+
domainsEnabled: true
46+
}, function(err, client) {
47+
test.ok(!err);
48+
var collection = client.collection('test');
49+
domainInstance.run(function() {
50+
collection.count({}, function(err) {
51+
test.ok(!err);
52+
test.ok(domainInstance === process.domain);
53+
domainInstance.exit();
54+
domainInstance.dispose();
55+
client.close();
56+
test.done();
57+
});
58+
});
59+
});
60+
}
61+
}
62+
63+
/**
64+
* @ignore
65+
*/
66+
exports.shouldStayInCorrectDomainForWriteCommand = {
67+
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
68+
69+
// The actual test we wish to run
70+
test: function(configuration, test) {
71+
var Domain = require('domain');
72+
var domainInstance = Domain.create();
73+
var client = configuration.newDbInstance({w: 1}, {poolSize: 1, auto_reconnect: true, domainsEnabled:true});
74+
75+
client.open(function(err, client) {
76+
test.ok(!err);
77+
var collection = client.collection('test');
78+
domainInstance.run(function() {
79+
collection.insert({field: 123}, function(err) {
80+
test.ok(!err);
81+
test.ok(domainInstance === process.domain);
82+
domainInstance.exit();
83+
domainInstance.dispose();
84+
client.close();
85+
test.done();
86+
});
87+
});
88+
});
89+
}
90+
}
91+
92+
/**
93+
* @ignore
94+
*/
95+
exports.shouldStayInCorrectDomainForQueuedReadCommand = {
96+
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
97+
98+
// The actual test we wish to run
99+
test: function(configuration, test) {
100+
var Domain = require('domain');
101+
var domainInstance = Domain.create();
102+
var client = configuration.newDbInstance({w: 0, bufferMaxEntries: 0}, {poolSize: 1, auto_reconnect: true, domainsEnabled:true});
103+
104+
client.open(function(err, client) {
105+
var connection = client.serverConfig.connections()[0];
106+
var collection = client.collection('test');
107+
connection.destroy();
108+
109+
domainInstance.run(function() {
110+
collection.count({}, function(err, c) {
111+
test.ok(err != null);
112+
test.ok(process.domain === domainInstance);
113+
domainInstance.exit();
114+
domainInstance.dispose();
115+
client.close();
116+
test.done();
117+
});
118+
});
119+
});
120+
}
121+
}
122+
123+
/**
124+
* @ignore
125+
*/
126+
exports.shouldStayInCorrectDomainForQueuedWriteCommand = {
127+
metadata: { requires: { node: ">=0.10.x", topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
128+
129+
// The actual test we wish to run
130+
test: function(configuration, test) {
131+
var Domain = require('domain');
132+
var domainInstance = Domain.create();
133+
var client = configuration.newDbInstance({w: 1, bufferMaxEntries: 0}, {poolSize: 1, auto_reconnect: true, domainsEnabled:true});
134+
135+
client.open(function(err, client) {
136+
test.ok(!err);
137+
var connection = client.serverConfig.connections()[0];
138+
var collection = client.collection('test');
139+
connection.destroy();
140+
141+
domainInstance.run(function() {
142+
collection.insert({field: 123}, function(err) {
143+
test.ok(err != null);
144+
test.ok(process.domain === domainInstance);
145+
domainInstance.exit();
146+
domainInstance.dispose();
147+
client.close();
148+
test.done();
149+
});
150+
});
151+
});
152+
}
153+
}

0 commit comments

Comments
 (0)