Skip to content

Commit af3243d

Browse files
committed
test(UnifiedTopology): fix a variety of issues with unified topology tests
The driver assumes that any connection string with only one host and doesn't have a replicaset name is Single. We used to accommodate this in the legacy Server topology by detecting if the connected server was a mongos, and switching under the hood to a legacy Mongos topology. However, SDAM (and by extension the Unified Topology) mandates that once the topology is Single it must stay Single forever. Passing a single host mongos in gets labeled as Single, which breaks any features that depend on it being a Mongos. We originally switched to one shard for stability reasons, but now that breaks our Transactions tests. So we are going back to multiple mongoses.
1 parent eb5dfc9 commit af3243d

File tree

5 files changed

+56
-11
lines changed

5 files changed

+56
-11
lines changed

test/environments.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,13 @@ class ShardedEnvironment extends EnvironmentBase {
137137
this.host = 'localhost';
138138
this.port = 51000;
139139

140-
// NOTE: only connect to a single shard because there can be consistency issues using
141-
// more, revolving around the inability for shards to keep up-to-date views of
142-
// changes to the world (such as dropping a database).
143-
this.url = 'mongodb://%slocalhost:51000/integration_tests';
140+
// TODO: we used to only connect to a single shard here b/c of consistency issues
141+
// revolving around the inability for shards to keep up-to-date views of
142+
// changes to the world (such as dropping a database). However, b/c the unified
143+
// topology treats a single shard like a Single topology instead of a Sharded
144+
// topology, we need to use multiple shards as much as possible to ensure that
145+
// we get sharded test coverage (looking at you transactions tests!)
146+
this.url = 'mongodb://%slocalhost:51000,localhost:51001/integration_tests';
144147

145148
this.writeConcernMax = { w: 'majority', wtimeout: 30000 };
146149
this.topology = (host, port, options) => {

test/functional/runner/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ function parseSessionOptions(options) {
221221
return result;
222222
}
223223

224-
const IGNORED_COMMANDS = new Set(['ismaster']);
224+
const IGNORED_COMMANDS = new Set(['ismaster', 'configureFailPoint']);
225225

226226
let displayCommands = false;
227227
function runTestSuiteTest(configuration, spec, context) {

test/functional/sessions_tests.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,19 @@ describe('Sessions', function() {
180180
this.skip();
181181
return;
182182
}
183-
184183
return testContext.setup(this.configuration);
185184
});
186185

187-
generateTopologyTests(testSuites, testContext);
186+
function testFilter(spec) {
187+
const SKIP_TESTS = [
188+
// These two tests need to run against multiple mongoses
189+
'Dirty explicit session is discarded',
190+
'Dirty implicit session is discarded (write)'
191+
];
192+
193+
return SKIP_TESTS.indexOf(spec.description) === -1;
194+
}
195+
196+
generateTopologyTests(testSuites, testContext, testFilter);
188197
});
189198
});

test/functional/sharding_read_preference_tests.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ describe('Sharding (Read Preference)', function() {
1919
// The actual test we wish to run
2020
test: function(done) {
2121
const configuration = this.configuration;
22+
const host = configuration.host;
23+
const port = configuration.port;
2224

25+
const url = `mongodb://${host}:${port}/sharded_test_db?w=1`;
2326
// Connect using the mongos connections
24-
var client = new MongoClient(configuration.url(), { w: 0, monitorCommands: true });
27+
var client = new MongoClient(url, { w: 0, monitorCommands: true });
2528
client.connect(function(err) {
2629
expect(err).to.not.exist;
2730
const db = client.db(configuration.db);
@@ -77,9 +80,12 @@ describe('Sharding (Read Preference)', function() {
7780
// The actual test we wish to run
7881
test: function(done) {
7982
const configuration = this.configuration;
83+
const host = configuration.host;
84+
const port = configuration.port;
8085

86+
const url = `mongodb://${host}:${port}/sharded_test_db?w=1`;
8187
// Connect using the mongos connections
82-
const client = new MongoClient(configuration.url(), { w: 0 });
88+
const client = new MongoClient(url, { w: 0 });
8389
client.connect(function(err) {
8490
expect(err).to.not.exist;
8591
const db = client.db(configuration.db);

test/functional/transactions_tests.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ describe('Transactions', function() {
3131
'commitTransaction retry succeeds on new mongos',
3232
'commitTransaction retry fails on new mongos',
3333
'unpin after transient error within a transaction and commit',
34-
'count'
34+
'count',
35+
// This test needs there to be multiple mongoses
36+
'increment txnNumber',
37+
// There is something wrong with the distinct command in the runner:
38+
// it is not failing properly
39+
'add transient label to connection errors'
3540
];
3641

3742
return SKIP_TESTS.indexOf(spec.description) === -1;
@@ -74,7 +79,7 @@ describe('Transactions', function() {
7479
metadata: { requires: { topology: ['sharded'], mongodb: '4.0.x' } },
7580
test: function(done) {
7681
const configuration = this.configuration;
77-
const client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 });
82+
const client = configuration.newClient(configuration.url());
7883

7984
client.connect((err, client) => {
8085
const session = client.startSession();
@@ -93,5 +98,27 @@ describe('Transactions', function() {
9398
});
9499
}
95100
});
101+
102+
it('should not error if transactions are supported', {
103+
metadata: { requires: { topology: ['sharded'], mongodb: '>=4.1.0' } },
104+
test: function(done) {
105+
const configuration = this.configuration;
106+
const client = configuration.newClient(configuration.url());
107+
108+
client.connect((err, client) => {
109+
const session = client.startSession();
110+
const db = client.db(configuration.db);
111+
const coll = db.collection('transaction_error_test');
112+
coll.insertOne({ a: 1 }, err => {
113+
expect(err).to.not.exist;
114+
expect(() => session.startTransaction()).to.not.throw();
115+
116+
session.endSession(() => {
117+
client.close(done);
118+
});
119+
});
120+
});
121+
}
122+
});
96123
});
97124
});

0 commit comments

Comments
 (0)