summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/stepdown_query.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/noPassthrough/stepdown_query.js')
-rw-r--r--jstests/noPassthrough/stepdown_query.js122
1 files changed, 61 insertions, 61 deletions
diff --git a/jstests/noPassthrough/stepdown_query.js b/jstests/noPassthrough/stepdown_query.js
index 6351493bbb4..4e8cc001840 100644
--- a/jstests/noPassthrough/stepdown_query.js
+++ b/jstests/noPassthrough/stepdown_query.js
@@ -8,72 +8,72 @@
TestData.skipCheckingUUIDsConsistentAcrossCluster = true;
(function() {
- 'use strict';
+'use strict';
- // Set the refresh period to 10 min to rule out races
- _setShellFailPoint({
- configureFailPoint: "modifyReplicaSetMonitorDefaultRefreshPeriod",
- mode: "alwaysOn",
- data: {
- period: 10 * 60,
- },
- });
-
- var dbName = "test";
- var collName = jsTest.name();
+// Set the refresh period to 10 min to rule out races
+_setShellFailPoint({
+ configureFailPoint: "modifyReplicaSetMonitorDefaultRefreshPeriod",
+ mode: "alwaysOn",
+ data: {
+ period: 10 * 60,
+ },
+});
- function runTest(host, rst, waitForPrimary) {
- // We create a new connection to 'host' here instead of passing in the original connection.
- // This to work around the fact that connections created by ReplSetTest already have slaveOk
- // set on them, but we need a connection with slaveOk not set for this test.
- var conn = new Mongo(host);
- var coll = conn.getDB(dbName).getCollection(collName);
- assert(!coll.exists());
- assert.writeOK(coll.insert([{}, {}, {}, {}, {}]));
- var cursor = coll.find().batchSize(2);
- // Retrieve the first batch of results.
- cursor.next();
- cursor.next();
- assert.eq(0, cursor.objsLeftInBatch());
- var primary = rst.getPrimary();
- var secondary = rst.getSecondary();
- assert.commandWorked(primary.getDB("admin").runCommand({replSetStepDown: 60, force: true}));
- rst.waitForState(primary, ReplSetTest.State.SECONDARY);
- if (waitForPrimary) {
- rst.waitForState(secondary, ReplSetTest.State.PRIMARY);
- }
- // When the primary steps down, it closes all client connections. Since 'conn' may be a
- // direct connection to the primary and the shell doesn't automatically retry operations on
- // network errors, we run a dummy operation here to force the shell to reconnect.
- try {
- conn.getDB("admin").runCommand("ping");
- } catch (e) {
- }
+var dbName = "test";
+var collName = jsTest.name();
- // Even though our connection doesn't have slaveOk set, we should still be able to iterate
- // our cursor and kill our cursor.
- assert(cursor.hasNext());
- assert.doesNotThrow(function() {
- cursor.close();
- });
+function runTest(host, rst, waitForPrimary) {
+ // We create a new connection to 'host' here instead of passing in the original connection.
+ // This to work around the fact that connections created by ReplSetTest already have slaveOk
+ // set on them, but we need a connection with slaveOk not set for this test.
+ var conn = new Mongo(host);
+ var coll = conn.getDB(dbName).getCollection(collName);
+ assert(!coll.exists());
+ assert.writeOK(coll.insert([{}, {}, {}, {}, {}]));
+ var cursor = coll.find().batchSize(2);
+ // Retrieve the first batch of results.
+ cursor.next();
+ cursor.next();
+ assert.eq(0, cursor.objsLeftInBatch());
+ var primary = rst.getPrimary();
+ var secondary = rst.getSecondary();
+ assert.commandWorked(primary.getDB("admin").runCommand({replSetStepDown: 60, force: true}));
+ rst.waitForState(primary, ReplSetTest.State.SECONDARY);
+ if (waitForPrimary) {
+ rst.waitForState(secondary, ReplSetTest.State.PRIMARY);
+ }
+ // When the primary steps down, it closes all client connections. Since 'conn' may be a
+ // direct connection to the primary and the shell doesn't automatically retry operations on
+ // network errors, we run a dummy operation here to force the shell to reconnect.
+ try {
+ conn.getDB("admin").runCommand("ping");
+ } catch (e) {
}
- // Test querying a replica set primary directly.
- var rst = new ReplSetTest({nodes: 1});
- rst.startSet();
- rst.initiate();
- runTest(rst.getPrimary().host, rst, false);
- rst.stopSet();
+ // Even though our connection doesn't have slaveOk set, we should still be able to iterate
+ // our cursor and kill our cursor.
+ assert(cursor.hasNext());
+ assert.doesNotThrow(function() {
+ cursor.close();
+ });
+}
+
+// Test querying a replica set primary directly.
+var rst = new ReplSetTest({nodes: 1});
+rst.startSet();
+rst.initiate();
+runTest(rst.getPrimary().host, rst, false);
+rst.stopSet();
- rst = new ReplSetTest({nodes: 2});
- rst.startSet();
- rst.initiate();
- runTest(rst.getURL(), rst, true);
- rst.stopSet();
+rst = new ReplSetTest({nodes: 2});
+rst.startSet();
+rst.initiate();
+runTest(rst.getURL(), rst, true);
+rst.stopSet();
- // Test querying a replica set primary through mongos.
- var st = new ShardingTest({shards: 1, rs: {nodes: 2}, config: 2});
- rst = st.rs0;
- runTest(st.s0.host, rst, true);
- st.stop();
+// Test querying a replica set primary through mongos.
+var st = new ShardingTest({shards: 1, rs: {nodes: 2}, config: 2});
+rst = st.rs0;
+runTest(st.s0.host, rst, true);
+st.stop();
})();