diff options
author | Rahul Sundararaman <rahul.sundararaman@mongodb.com> | 2019-10-08 20:10:48 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-10-08 20:10:48 +0000 |
commit | 946189b0389432037c248835c8f2924d7a0c8e5d (patch) | |
tree | 416eafcfd35f4985b9f8dfbad3e539dbdf23499e /jstests/sharding | |
parent | 4540bfd836c2d50979dba01ef3be38f975fb75af (diff) | |
download | mongo-946189b0389432037c248835c8f2924d7a0c8e5d.tar.gz |
SERVER-42407 Sharding/read_pref_cmd.js should assume less about secondaryPreferred + tag_sets
Diffstat (limited to 'jstests/sharding')
-rw-r--r-- | jstests/sharding/read_pref_cmd.js | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/jstests/sharding/read_pref_cmd.js b/jstests/sharding/read_pref_cmd.js index c869b9bafbe..35f76d1d567 100644 --- a/jstests/sharding/read_pref_cmd.js +++ b/jstests/sharding/read_pref_cmd.js @@ -45,9 +45,9 @@ var tearDown = function() { * @param isMongos {boolean} true if conn is a mongos connection. * @param mode {string} a read preference mode like 'secondary' * @param tagSets {Array.<Object>} list of tag sets to use - * @param secExpected {boolean} true if we expect to run any commands on secondary + * @param expectedHost {string} which host should this run on: 'primary', 'secondary', or 'any' */ -var testReadPreference = function(conn, hostList, isMongos, mode, tagSets, secExpected) { +var testReadPreference = function(conn, hostList, isMongos, mode, tagSets, expectedHost) { var testDB = conn.getDB('test'); var adminDB = conn.getDB('admin'); conn.setSlaveOk(false); // purely rely on readPref @@ -85,11 +85,11 @@ var testReadPreference = function(conn, hostList, isMongos, mode, tagSets, secEx var result = profileDB.system.profile.findOne(query); if (result != null) { - if (secOk && secExpected) { + if (secOk && expectedHost == "secondary") { // The command obeys read prefs and we expect to run // commands on secondaries with this mode and tag sets assert(profileDB.adminCommand({isMaster: 1}).secondary); - } else { + } else if (expectedHost == "primary") { // The command does not obey read prefs, or we expect to run // commands on primary with this mode or tag sets assert(profileDB.adminCommand({isMaster: 1}).ismaster); @@ -253,33 +253,33 @@ var testAllModes = function(conn, hostList, isMongos) { // a bunch of combinations. [ // mode, tagSets, expectedHost - ['primary', undefined, false], - ['primary', [], false], + ['primary', undefined, "primary"], + ['primary', [], "primary"], - ['primaryPreferred', undefined, false], - ['primaryPreferred', [{tag: 'one'}], false], + ['primaryPreferred', undefined, "any"], + ['primaryPreferred', [{tag: 'one'}], "primary"], // Correctly uses primary and ignores the tag - ['primaryPreferred', [{tag: 'two'}], false], + ['primaryPreferred', [{tag: 'two'}], "any"], - ['secondary', undefined, true], - ['secondary', [{tag: 'two'}], true], - ['secondary', [{tag: 'doesntexist'}, {}], true], - ['secondary', [{tag: 'doesntexist'}, {tag: 'two'}], true], + ['secondary', undefined, "secondary"], + ['secondary', [{tag: 'two'}], "secondary"], + ['secondary', [{tag: 'doesntexist'}, {}], "secondary"], + ['secondary', [{tag: 'doesntexist'}, {tag: 'two'}], "secondary"], - ['secondaryPreferred', undefined, true], - ['secondaryPreferred', [{tag: 'one'}], false], - ['secondaryPreferred', [{tag: 'two'}], true], + ['secondaryPreferred', undefined, "any"], + ['secondaryPreferred', [{tag: 'one'}], "primary"], + ['secondaryPreferred', [{tag: 'two'}], "any"], // We don't have a way to alter ping times so we can't predict where an // untagged 'nearest' command should go, hence only test with tags. - ['nearest', [{tag: 'one'}], false], - ['nearest', [{tag: 'two'}], true] + ['nearest', [{tag: 'one'}], "any"], + ['nearest', [{tag: 'two'}], "any"] ].forEach(function(args) { - var mode = args[0], tagSets = args[1], secExpected = args[2]; + var mode = args[0], tagSets = args[1], expectedHost = args[2]; setUp(); - testReadPreference(conn, hostList, isMongos, mode, tagSets, secExpected); + testReadPreference(conn, hostList, isMongos, mode, tagSets, expectedHost); tearDown(); }); |