summaryrefslogtreecommitdiff
path: root/jstests/core
diff options
context:
space:
mode:
authorRobert Guo <robert.guo@10gen.com>2016-02-09 13:47:28 -0500
committerRobert Guo <robert.guo@10gen.com>2016-02-09 18:51:46 -0500
commit8fce2322ec5a85181792cbf8a950e1ac14805578 (patch)
tree520d9be2f43c577977f442fcda482bdeac9da883 /jstests/core
parent68614480bd2aa45721bdf177c0bf558e78e8cb0f (diff)
downloadmongo-8fce2322ec5a85181792cbf8a950e1ac14805578.tar.gz
SERVER-22234 The Validate Command Should Work with failIndexKeyTooLong
Diffstat (limited to 'jstests/core')
-rw-r--r--jstests/core/index_bigkeys_nofail.js4
-rw-r--r--jstests/core/index_bigkeys_validation.js32
2 files changed, 36 insertions, 0 deletions
diff --git a/jstests/core/index_bigkeys_nofail.js b/jstests/core/index_bigkeys_nofail.js
index 5a2e407a1a2..417470d7f04 100644
--- a/jstests/core/index_bigkeys_nofail.js
+++ b/jstests/core/index_bigkeys_nofail.js
@@ -46,4 +46,8 @@
assert.writeError(t.update({_id: 3}, {$set:{name: x}}));
db.getSiblingDB('admin').runCommand( { setParameter: 1, failIndexKeyTooLong: was } );
+
+ // Explicitly drop the collection to avoid failures in post-test hooks that run dbHash and
+ // validate commands.
+ t.drop();
}());
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();
+})();