Skip to content

Commit

Permalink
Ensure read preference is never overriden, so DB config prevails (#4833)
Browse files Browse the repository at this point in the history
  • Loading branch information
flovilmart authored Jun 13, 2018
1 parent 1e29d02 commit 9c9c07f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
25 changes: 15 additions & 10 deletions spec/ReadPreferenceOption.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ describe_only_db('mongo')('Read preference option', () => {
let myObjectReadPreference = null;
databaseAdapter.database.serverConfig.cursor.calls.all().forEach((call) => {
if (call.args[0].indexOf('MyObject') >= 0) {
myObjectReadPreference = call.args[2].readPreference.preference;
myObjectReadPreference = true;
expect(call.args[2].readPreference).toBeUndefined();
}
});

expect(myObjectReadPreference).toEqual(ReadPreference.PRIMARY);
expect(myObjectReadPreference).toBe(true);

done();
});
Expand Down Expand Up @@ -442,18 +443,20 @@ describe_only_db('mongo')('Read preference option', () => {
let myObjectReadPreference2 = null;
databaseAdapter.database.serverConfig.cursor.calls.all().forEach((call) => {
if (call.args[0].indexOf('MyObject0') >= 0) {
myObjectReadPreference0 = call.args[2].readPreference.preference;
myObjectReadPreference0 = true;
expect(call.args[2].readPreference).toBeUndefined();
}
if (call.args[0].indexOf('MyObject1') >= 0) {
myObjectReadPreference1 = call.args[2].readPreference.preference;
myObjectReadPreference1 = true;
expect(call.args[2].readPreference).toBeUndefined();
}
if (call.args[0].indexOf('MyObject2') >= 0) {
myObjectReadPreference2 = call.args[2].readPreference.preference;
}
});

expect(myObjectReadPreference0).toEqual(ReadPreference.PRIMARY);
expect(myObjectReadPreference1).toEqual(ReadPreference.PRIMARY);
expect(myObjectReadPreference0).toBe(true);
expect(myObjectReadPreference1).toBe(true);
expect(myObjectReadPreference2).toEqual(ReadPreference.SECONDARY);

done();
Expand Down Expand Up @@ -555,18 +558,20 @@ describe_only_db('mongo')('Read preference option', () => {
let myObjectReadPreference2 = null;
databaseAdapter.database.serverConfig.cursor.calls.all().forEach((call) => {
if (call.args[0].indexOf('MyObject0') >= 0) {
myObjectReadPreference0 = call.args[2].readPreference.preference;
myObjectReadPreference0 = true;
expect(call.args[2].readPreference).toBeUndefined();
}
if (call.args[0].indexOf('MyObject1') >= 0) {
myObjectReadPreference1 = call.args[2].readPreference.preference;
myObjectReadPreference1 = true;
expect(call.args[2].readPreference).toBeUndefined();
}
if (call.args[0].indexOf('MyObject2') >= 0) {
myObjectReadPreference2 = call.args[2].readPreference.preference;
}
});

expect(myObjectReadPreference0).toEqual(ReadPreference.PRIMARY);
expect(myObjectReadPreference1).toEqual(ReadPreference.PRIMARY);
expect(myObjectReadPreference0).toBe(true);
expect(myObjectReadPreference1).toBe(true);
expect(myObjectReadPreference2).toEqual(ReadPreference.SECONDARY);

done();
Expand Down
2 changes: 0 additions & 2 deletions src/Adapters/Storage/Mongo/MongoStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,6 @@ export class MongoStorageAdapter implements StorageAdapter {
readPreference = ReadPreference.NEAREST;
break;
case undefined:
// this is to match existing tests, which were failing as mongodb@3.0 don't report readPreference anymore
readPreference = ReadPreference.PRIMARY;
break;
default:
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Not supported read preference.');
Expand Down

0 comments on commit 9c9c07f

Please sign in to comment.