summaryrefslogtreecommitdiff
path: root/jstests/replsets/initial_sync_replSetGetStatus.js
diff options
context:
space:
mode:
authorJudah Schvimer <judah@mongodb.com>2017-03-16 18:08:49 -0400
committerJudah Schvimer <judah@mongodb.com>2017-03-16 18:08:49 -0400
commitf53a88a57da5788b355cb3037061372a706ccf0d (patch)
tree7a62a074b6dcdcbdc324a37207df1eff5ae8eede /jstests/replsets/initial_sync_replSetGetStatus.js
parent5fe822f53e4bb28e15af2541c0ca931fa05a0e20 (diff)
downloadmongo-f53a88a57da5788b355cb3037061372a706ccf0d.tar.gz
SERVER-26772 removed old initial sync code
Diffstat (limited to 'jstests/replsets/initial_sync_replSetGetStatus.js')
-rw-r--r--jstests/replsets/initial_sync_replSetGetStatus.js90
1 files changed, 90 insertions, 0 deletions
diff --git a/jstests/replsets/initial_sync_replSetGetStatus.js b/jstests/replsets/initial_sync_replSetGetStatus.js
new file mode 100644
index 00000000000..265a393374f
--- /dev/null
+++ b/jstests/replsets/initial_sync_replSetGetStatus.js
@@ -0,0 +1,90 @@
+/**
+ * This test tests that replSetGetStatus returns initial sync stats while initial sync is in
+ * progress.
+ */
+
+(function() {
+ "use strict";
+ load("jstests/libs/check_log.js");
+
+ var name = 'initial_sync_replSetGetStatus';
+ var replSet = new ReplSetTest({
+ name: name,
+ nodes: 1,
+ });
+
+ replSet.startSet();
+ replSet.initiate();
+ var primary = replSet.getPrimary();
+
+ var coll = primary.getDB('test').foo;
+ assert.writeOK(coll.insert({a: 1}));
+ assert.writeOK(coll.insert({a: 2}));
+
+ // Add a secondary node but make it hang before copying databases.
+ var secondary = replSet.add();
+ secondary.setSlaveOk();
+
+ assert.commandWorked(secondary.getDB('admin').runCommand(
+ {configureFailPoint: 'initialSyncHangBeforeCopyingDatabases', mode: 'alwaysOn'}));
+ assert.commandWorked(secondary.getDB('admin').runCommand(
+ {configureFailPoint: 'initialSyncHangBeforeFinish', mode: 'alwaysOn'}));
+ replSet.reInitiate();
+
+ // Wait for initial sync to pause before it copies the databases.
+ checkLog.contains(secondary,
+ 'initial sync - initialSyncHangBeforeCopyingDatabases fail point enabled');
+
+ // Test that replSetGetStatus returns the correct results while initial sync is in progress.
+ var res = assert.commandWorked(secondary.adminCommand({replSetGetStatus: 1}));
+ assert(!res.initialSyncStatus,
+ "Response should not have an 'initialSyncStatus' field: " + tojson(res));
+
+ res = assert.commandWorked(secondary.adminCommand({replSetGetStatus: 1, initialSync: 1}));
+ assert(res.initialSyncStatus,
+ "Response should have an 'initialSyncStatus' field: " + tojson(res));
+
+ assert.commandFailed(secondary.adminCommand({replSetGetStatus: 1, initialSync: "t"}),
+ ErrorCodes.TypeMismatch);
+
+ assert.writeOK(coll.insert({a: 3}));
+ assert.writeOK(coll.insert({a: 4}));
+
+ // Let initial sync continue working.
+ assert.commandWorked(secondary.getDB('admin').runCommand(
+ {configureFailPoint: 'initialSyncHangBeforeCopyingDatabases', mode: 'off'}));
+
+ // Wait for initial sync to pause right before it finishes.
+ checkLog.contains(secondary, 'initial sync - initialSyncHangBeforeFinish fail point enabled');
+
+ // Test that replSetGetStatus returns the correct results when initial sync is at the very end.
+ res = assert.commandWorked(secondary.adminCommand({replSetGetStatus: 1, initialSync: 1}));
+ assert(res.initialSyncStatus, "Response should have an 'initialSyncStatus' field.");
+ assert.eq(res.initialSyncStatus.fetchedMissingDocs, 0);
+ assert.eq(res.initialSyncStatus.appliedOps, 2);
+ assert.eq(res.initialSyncStatus.failedInitialSyncAttempts, 0);
+ assert.eq(res.initialSyncStatus.maxFailedInitialSyncAttempts, 1);
+ assert.eq(res.initialSyncStatus.databases.databasesCloned, 2);
+ assert.eq(res.initialSyncStatus.databases.test.collections, 1);
+ assert.eq(res.initialSyncStatus.databases.test.clonedCollections, 1);
+ assert.eq(res.initialSyncStatus.databases.test["test.foo"].documentsToCopy, 4);
+ assert.eq(res.initialSyncStatus.databases.test["test.foo"].documentsCopied, 4);
+ assert.eq(res.initialSyncStatus.databases.test["test.foo"].indexes, 1);
+ assert.eq(res.initialSyncStatus.databases.test["test.foo"].fetchedBatches, 1);
+
+ // Let initial sync finish and get into secondary state.
+ assert.commandWorked(secondary.getDB('admin').runCommand(
+ {configureFailPoint: 'initialSyncHangBeforeFinish', mode: 'off'}));
+ replSet.awaitSecondaryNodes(60 * 1000);
+
+ // Test that replSetGetStatus returns the correct results after initial sync is finished.
+ res = assert.commandWorked(secondary.adminCommand({replSetGetStatus: 1}));
+ assert(!res.initialSyncStatus,
+ "Response should not have an 'initialSyncStatus' field: " + tojson(res));
+
+ assert.commandFailedWithCode(secondary.adminCommand({replSetGetStatus: 1, initialSync: "m"}),
+ ErrorCodes.TypeMismatch);
+ assert.eq(0,
+ secondary.getDB('local')['temp_oplog_buffer'].find().itcount(),
+ "Oplog buffer was not dropped after initial sync");
+})();