diff options
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/replsets/stepdown.js | 11 | ||||
-rw-r--r-- | jstests/sharding/read_pref_cmd.js | 13 |
2 files changed, 17 insertions, 7 deletions
diff --git a/jstests/replsets/stepdown.js b/jstests/replsets/stepdown.js index 275d7726d40..404864f2b92 100644 --- a/jstests/replsets/stepdown.js +++ b/jstests/replsets/stepdown.js @@ -5,6 +5,11 @@ load("jstests/replsets/rslib.js") +// utility to check if an error was due to connection failure. +var errorWasDueToConnectionFailure = function(error) { + return tojson(error).indexOf("transport error") > 0; +}; + var replTest = new ReplSetTest({ name: 'testSet', nodes: 2, nodeOptions: {verbose: 1} }); var nodes = replTest.startSet(); replTest.initiate(); @@ -92,7 +97,9 @@ try { assert.commandWorked(master.getDB("admin").runCommand({replSetStepDown : 100, force : true})); } catch (e) { - if (tojson( e ).indexOf( "error doing query: failed" ) < 0) { + // ignore errors due to connection failures as we expect the master to close connections + // on stepdown + if (!errorWasDueToConnectionFailure(e)) { throw e; } } @@ -173,7 +180,7 @@ try { printjson(currentMaster.getDB("admin").runCommand({shutdown : 1, force : true})); } catch (e) { - if (tojson(e).indexOf( "error doing query: failed" ) < 0) { + if (!errorWasDueToConnectionFailure(e)) { throw e; } } diff --git a/jstests/sharding/read_pref_cmd.js b/jstests/sharding/read_pref_cmd.js index 57c9b55d8a9..520d8c6eecb 100644 --- a/jstests/sharding/read_pref_cmd.js +++ b/jstests/sharding/read_pref_cmd.js @@ -53,7 +53,9 @@ var testReadPreference = function(conn, hostList, isMongos, mode, tagSets, secEx */ var cmdTest = function(cmdObj, secOk, profileQuery) { jsTest.log('about to do: ' + tojson(cmdObj)); - var cmdResult = testDB.runCommand(cmdObj); + // use runReadCommand so that the cmdObj is modified with the readPreference + // set on the connection. + var cmdResult = testDB.runReadCommand(cmdObj); jsTest.log('cmd result: ' + tojson(cmdResult)); assert(cmdResult.ok); @@ -180,19 +182,20 @@ var testBadMode = function(conn, hostList, isMongos, mode, tagSets) { var failureMsg, testDB, cmdResult; jsTest.log('Expecting failure for mode: ' + mode + ', tag sets: ' + tojson(tagSets)); - conn.setReadPref(mode, tagSets); + // use setReadPrefUnsafe to bypass client-side validation + conn._setReadPrefUnsafe(mode, tagSets); testDB = conn.getDB('test'); // Test that a command that could be routed to a secondary fails with bad mode / tags. if (isMongos) { // Command result should have ok: 0. - cmdResult = testDB.runCommand({ distinct: 'user', key: 'x' }); + cmdResult = testDB.runReadCommand({ distinct: 'user', key: 'x' }); jsTest.log('cmd result: ' + tojson(cmdResult)); assert(!cmdResult.ok); } else { try { // conn should throw error - testDB.runCommand({ distinct: 'user', key: 'x' }); + testDB.runReadCommand({ distinct: 'user', key: 'x' }); failureMsg = "Unexpected success running distinct!"; } catch (e) { @@ -211,7 +214,7 @@ var testAllModes = function(conn, hostList, isMongos) { [ // mode, tagSets, expectedHost ['primary', undefined, false], - ['primary', [{}], false], + ['primary', [], false], ['primaryPreferred', undefined, false], ['primaryPreferred', [{tag: 'one'}], false], |