summaryrefslogtreecommitdiff
path: root/jstests/core/long_index_rename.js
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2018-06-27 17:53:03 -0400
committerBenety Goh <benety@mongodb.com>2018-06-27 17:53:03 -0400
commita3e1ba4eb1798def823ada738f96b42e5417adee (patch)
tree057345b462a85c870043ac9f5b510fd40f1319f1 /jstests/core/long_index_rename.js
parentf0f2530e83db70d89a12298a25ba2cde35cf0990 (diff)
downloadmongo-a3e1ba4eb1798def823ada738f96b42e5417adee.tar.gz
SERVER-32959 clean up tests before removing index namespace constraints
add RenameCollectionTest test case for long collection name clean up long_index_rename.js clean up ns_length.js clean up rename6.js
Diffstat (limited to 'jstests/core/long_index_rename.js')
-rw-r--r--jstests/core/long_index_rename.js32
1 files changed, 21 insertions, 11 deletions
diff --git a/jstests/core/long_index_rename.js b/jstests/core/long_index_rename.js
index 507c53921ef..b1e7fb91b96 100644
--- a/jstests/core/long_index_rename.js
+++ b/jstests/core/long_index_rename.js
@@ -3,16 +3,26 @@
// but this caused secondaries to crash when replicating what should be a bad createIndex command.
// Here we test that the too-long name is rejected in this situation as well
-t = db.long_index_rename;
-t.drop();
+(function() {
+ 'use strict';
-for (i = 1; i < 10; i++) {
- t.save({a: i});
-}
+ const coll = db.long_index_rename;
+ coll.drop();
-t.createIndex({a: 1}, {name: "aaa"});
-var result = t.createIndex({a: 1}, {
- name: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
-});
-assert(!result.ok);
+ for (let i = 1; i < 10; i++) {
+ coll.save({a: i});
+ }
+
+ // Compute maximum index name length for this collection under FCV 4.0.
+ const maxNsLength = 127;
+ const maxIndexNameLength = maxNsLength - (coll.getFullName() + ".$").length;
+ jsTestLog('Max index name length under FCV 4.0 = ' + maxIndexNameLength);
+
+ // Create an index with the longest name allowed for this collection.
+ assert.commandWorked(coll.createIndex({a: 1}, {name: 'a'.repeat(maxIndexNameLength)}));
+
+ // Index namespaces longer than 127 characters are not acceptable.
+ assert.commandFailedWithCode(
+ coll.createIndex({b: 1}, {name: 'b'.repeat(maxIndexNameLength) + 1}),
+ ErrorCodes.CannotCreateIndex);
+})();