summaryrefslogtreecommitdiff
path: root/jstests/core/index_bigkeys_validation.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/core/index_bigkeys_validation.js')
-rw-r--r--jstests/core/index_bigkeys_validation.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/jstests/core/index_bigkeys_validation.js b/jstests/core/index_bigkeys_validation.js
new file mode 100644
index 00000000000..ef29b07ecc7
--- /dev/null
+++ b/jstests/core/index_bigkeys_validation.js
@@ -0,0 +1,32 @@
+// Tests that index validation succeeds for long keys when failIndexKeyTooLong is set to false.
+// See: SERVER-22234
+'use strict';
+
+(function() {
+ var coll = db.longindex;
+ coll.drop();
+
+ var longVal = new Array(1025).join('x'); // Keys >= 1024 bytes cannot be indexed.
+
+ assert.commandWorked(db.adminCommand({setParameter: 1, failIndexKeyTooLong: false}));
+
+ assert.writeOK(coll.insert({_id: longVal}));
+ // Verify that validation succeeds when the failIndexKeyTooLong parameter is set to false,
+ // even when there are fewer index keys than documents.
+ var res = coll.validate({full: true, scandata: true});
+ assert.commandWorked(res);
+ assert(res.valid, tojson(res));
+
+ // Change failIndexKeyTooLong back to the default value.
+ assert.commandWorked(db.adminCommand({setParameter: 1, failIndexKeyTooLong: true}));
+
+ // Verify that validation fails when the failIndexKeyTooLong parameter is
+ // reverted to its old value and there are mismatched index keys and documents.
+ res = coll.validate({full: true, scandata: true});
+ assert.commandWorked(res);
+ assert.eq(res.valid, false, tojson(res));
+
+ // Explicitly drop the collection to avoid failures in post-test hooks that run dbHash and
+ // validate commands.
+ coll.drop();
+})();