diff options
author | Cheahuychou Mao <cheahuychou.mao@mongodb.com> | 2020-04-13 12:03:49 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-04-14 15:56:38 +0000 |
commit | 8b81217b65fa99c2391d248a879a43749e2f16b4 (patch) | |
tree | 91d99b873f2cd91fbdea2aff7e67fddf08212d8e /jstests | |
parent | 4763d4169e0f1535308ac56c741ac3afd2e5dbd2 (diff) | |
download | mongo-8b81217b65fa99c2391d248a879a43749e2f16b4.tar.gz |
SERVER-47047 Add tests that mongos does not mark a node as down when reads fail
(cherry picked from commit b4f1c5ed8af0ed6340c1795071ed061ae7facf14)
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/sharding/mongos_not_mark_nodes_as_down_when_reads_fail.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/jstests/sharding/mongos_not_mark_nodes_as_down_when_reads_fail.js b/jstests/sharding/mongos_not_mark_nodes_as_down_when_reads_fail.js new file mode 100644 index 00000000000..90e9774ef8c --- /dev/null +++ b/jstests/sharding/mongos_not_mark_nodes_as_down_when_reads_fail.js @@ -0,0 +1,69 @@ +/* + * Tests that mongos does not mark nodes as down when reads fail. + */ +(function() { +'use strict'; + +load("jstests/libs/fail_point_util.js"); + +/* + * Configures failCommand to force the given command to fail with the given error code when run + * on the given namespace, and returns the resulting fail point. + */ +function configureFailCommand(nodeConn, command, ns, error) { + return configureFailPoint( + nodeConn, + "failCommand", + {failInternalCommands: true, errorCode: error, failCommands: [command], namespace: ns}); +} + +const st = new ShardingTest({shards: 1, rs: {nodes: [{}, {rsConfig: {priority: 0}}]}}); +const kDbName = "foo"; +const kCollName = "bar"; +const kNs = kDbName + "." + kCollName; +const kErrorCode = ErrorCodes.HostUnreachable; +const testDB = st.s.getDB(kDbName); + +assert.commandWorked(st.s.adminCommand({enableSharding: kDbName})); +assert.commandWorked(st.s.adminCommand({shardCollection: kNs, key: {x: 1}})); + +jsTest.log("Test that mongos does not mark the primary node as down when reads fail"); +(() => { + const cmdObj = { + count: kCollName, + query: {x: {$gte: 0}}, + $readPreference: {mode: "primary"}, + }; + + // Make the command fail on the primary node with HostUnreachable. + const failPoint = configureFailCommand(st.rs0.nodes[0], "count", kNs, kErrorCode); + assert.commandFailedWithCode(testDB.runCommand(cmdObj), kErrorCode); + failPoint.off(); + + // Verify that the node was not marked as down (i.e. it is still the primary node and the + // command with readPreference "primary" works). + awaitRSClientHosts(st.s, st.rs0.nodes[0], {ok: true, ismaster: true}); + assert.commandWorked(testDB.runCommand(cmdObj)); +})(); + +jsTest.log("Test that mongos does not mark the secondary node as down when reads fail"); +(() => { + const cmdObj = { + count: kCollName, + query: {x: {$gte: 0}}, + $readPreference: {mode: "secondary"}, + }; + + // Make the command fail on the secondary node. + const failPoint = configureFailCommand(st.rs0.nodes[1], "count", kNs, kErrorCode); + assert.commandFailedWithCode(testDB.runCommand(cmdObj), kErrorCode); + failPoint.off(); + + // Verify that the node was not marked as down (i.e. it is still the secondary node and the + // command with readPreference "secondary" works). + awaitRSClientHosts(st.s, st.rs0.nodes[1], {ok: true, secondary: true}); + assert.commandWorked(testDB.runCommand(cmdObj)); +})(); + +st.stop(); +})(); |