Skip to content

Commit

Permalink
fix(ReadPreference): improve ReadPreference error message and remove …
Browse files Browse the repository at this point in the history
…irrelevant sharding test
  • Loading branch information
kvwalker authored and daprahamian committed Aug 13, 2019
1 parent 06bbef2 commit dd34ce4
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 60 deletions.
4 changes: 1 addition & 3 deletions lib/core/topologies/read_preference.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
const ReadPreference = function(mode, tags, options) {
if (!ReadPreference.isValid(mode)) {
throw new TypeError(`provided mode ${mode} is an invalid ReadPreference mode`);
throw new TypeError(`Invalid read preference mode ${mode}`);
}

// TODO(major): tags MUST be an array of tagsets
Expand Down Expand Up @@ -81,8 +81,6 @@ const VALID_MODES = [
ReadPreference.SECONDARY,
ReadPreference.SECONDARY_PREFERRED,
ReadPreference.NEAREST,
// true,
// false,
null
];

Expand Down
2 changes: 1 addition & 1 deletion test/functional/readpreference_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ describe('ReadPreference', function() {
client.connect((err, client) => {
const db = client.db(configuration.db);
expect(db.collection.bind(db, 'test', { readPreference: 'invalid' })).to.throw(
'provided mode invalid is an invalid ReadPreference mode'
'Invalid read preference mode invalid'
);
client.close();
done();
Expand Down
56 changes: 0 additions & 56 deletions test/functional/sharding_read_preference_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,62 +68,6 @@ describe('Sharding (Read Preference)', function() {
}
});

/**
* @ignore
*/
it('Should correctly fail a Mongos read using a unsupported read preference', {
metadata: { requires: { topology: 'sharded' } },

// The actual test we wish to run
test: function(done) {
const configuration = this.configuration;

// Connect using the mongos connections
const client = new MongoClient(configuration.url(), { w: 0 });
client.connect(function(err) {
expect(err).to.not.exist;
const db = client.db(configuration.db);

// Perform a simple insert into a collection
const collection = db.collection('shard_test2');
// Insert a simple doc
collection.insertOne({ test: 1 }, { w: 'majority', wtimeout: 10000 }, function(err) {
expect(err).to.not.exist;

// Set debug level for the driver
Logger.setLevel('debug');

let gotMessage = false;
// Get the current logger
Logger.setCurrentLogger(function(message, options) {
if (
options.type === 'debug' &&
options.className === 'Cursor' &&
options.message.indexOf('"mode":"notsupported"') !== -1
) {
gotMessage = true;
}
});

collection.findOne(
{ test: 1 },
{ readPreference: new ReadPreference('notsupported') },
function(err) {
expect(err).to.exist;
expect(gotMessage).to.equal(true);

// Set error level for the driver
Logger.setLevel('error');
// Close db connection
client.close();
done();
}
);
});
});
}
});

/**
* @ignore
*/
Expand Down

0 comments on commit dd34ce4

Please sign in to comment.