summaryrefslogtreecommitdiff
path: root/jstests/replsets/collate_id.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/replsets/collate_id.js')
-rw-r--r--jstests/replsets/collate_id.js96
1 files changed, 49 insertions, 47 deletions
diff --git a/jstests/replsets/collate_id.js b/jstests/replsets/collate_id.js
index 6e6d56bc67d..588c02e979a 100644
--- a/jstests/replsets/collate_id.js
+++ b/jstests/replsets/collate_id.js
@@ -1,66 +1,68 @@
// Test that oplog application on the secondary happens correctly when the collection has a default
// collation and operations by _id which must respect the collation are issued.
(function() {
- "use strict";
+"use strict";
- Random.setRandomSeed();
+Random.setRandomSeed();
- // Return a string whose character at index 'i' in 'str' is replaced by 'character'.
- function replaceChar(str, i, character) {
- assert.eq(1, character.length);
- return str.substr(0, i) + character + str.substr(i + 1);
- }
+// Return a string whose character at index 'i' in 'str' is replaced by 'character'.
+function replaceChar(str, i, character) {
+ assert.eq(1, character.length);
+ return str.substr(0, i) + character + str.substr(i + 1);
+}
- // Return a string whose character at index 'i' has been uppercased.
- function uppercaseIth(str, i) {
- return replaceChar(str, i, str[i].toUpperCase());
- }
+// Return a string whose character at index 'i' has been uppercased.
+function uppercaseIth(str, i) {
+ return replaceChar(str, i, str[i].toUpperCase());
+}
- const caseInsensitive = {collation: {locale: "en_US", strength: 2}};
+const caseInsensitive = {
+ collation: {locale: "en_US", strength: 2}
+};
- var replTest = new ReplSetTest({name: 'testSet', nodes: 2});
- var nodes = replTest.startSet();
- replTest.initiate();
+var replTest = new ReplSetTest({name: 'testSet', nodes: 2});
+var nodes = replTest.startSet();
+replTest.initiate();
- var primary = replTest.getPrimary();
- var primaryDB = primary.getDB("test");
- var primaryColl = primaryDB.collate_id;
+var primary = replTest.getPrimary();
+var primaryDB = primary.getDB("test");
+var primaryColl = primaryDB.collate_id;
- var secondary = replTest.getSecondary();
- var secondaryDB = secondary.getDB("test");
- var secondaryColl = secondaryDB.collate_id;
+var secondary = replTest.getSecondary();
+var secondaryDB = secondary.getDB("test");
+var secondaryColl = secondaryDB.collate_id;
- // Stop the secondary from syncing. This will ensure that the writes on the primary get applied
- // on the secondary in a large batch.
- assert.commandWorked(
- secondaryDB.adminCommand({configureFailPoint: "rsSyncApplyStop", mode: "alwaysOn"}));
+// Stop the secondary from syncing. This will ensure that the writes on the primary get applied
+// on the secondary in a large batch.
+assert.commandWorked(
+ secondaryDB.adminCommand({configureFailPoint: "rsSyncApplyStop", mode: "alwaysOn"}));
- assert.commandWorked(primaryDB.createCollection(primaryColl.getName(), caseInsensitive));
+assert.commandWorked(primaryDB.createCollection(primaryColl.getName(), caseInsensitive));
- // A string of the character 'b' repeated.
- const baseStr = new Array(50).join("b");
+// A string of the character 'b' repeated.
+const baseStr = new Array(50).join("b");
- for (var i = 0; i < 1000; i++) {
- // Make an _id by uppercasing each character in "baseStr" with 0.5 probability.
- var strId = baseStr;
- for (var charIdx = 0; charIdx < baseStr.length; charIdx++) {
- if (Random.rand() < 0.5) {
- strId = uppercaseIth(strId, charIdx);
- }
+for (var i = 0; i < 1000; i++) {
+ // Make an _id by uppercasing each character in "baseStr" with 0.5 probability.
+ var strId = baseStr;
+ for (var charIdx = 0; charIdx < baseStr.length; charIdx++) {
+ if (Random.rand() < 0.5) {
+ strId = uppercaseIth(strId, charIdx);
}
-
- assert.writeOK(primaryColl.insert({_id: strId}));
- assert.writeOK(primaryColl.remove({_id: strId}));
}
- // Since the inserts and deletes happen in pairs, we should be left with an empty collection on
- // the primary.
- assert.eq(0, primaryColl.find().itcount());
+ assert.writeOK(primaryColl.insert({_id: strId}));
+ assert.writeOK(primaryColl.remove({_id: strId}));
+}
+
+// Since the inserts and deletes happen in pairs, we should be left with an empty collection on
+// the primary.
+assert.eq(0, primaryColl.find().itcount());
- // Allow the secondary to sync, and test that it also ends up with an empty collection.
- assert.commandWorked(
- secondaryDB.adminCommand({configureFailPoint: "rsSyncApplyStop", mode: "off"}));
- replTest.awaitReplication();
- assert.eq(0, secondaryColl.find().itcount());
- replTest.stopSet();
+// Allow the secondary to sync, and test that it also ends up with an empty collection.
+assert.commandWorked(
+ secondaryDB.adminCommand({configureFailPoint: "rsSyncApplyStop", mode: "off"}));
+replTest.awaitReplication();
+assert.eq(0, secondaryColl.find().itcount());
+replTest.stopSet();
})();