diff options
author | Benety Goh <benety@mongodb.com> | 2021-08-05 21:28:03 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-08-06 01:49:20 +0000 |
commit | 422ea6580389e5f8f0eacd19257481bf3ef63e5d (patch) | |
tree | bc2fbc124d0291e6c315a451c8d59eabc597f949 /jstests | |
parent | bcf237d9a7e319cd9d92cec7702fcc689c18931f (diff) | |
download | mongo-422ea6580389e5f8f0eacd19257481bf3ef63e5d.tar.gz |
SERVER-59096 clean up index_many2.js
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/core/index_many2.js | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/jstests/core/index_many2.js b/jstests/core/index_many2.js index 80169d11e10..73dc910a796 100644 --- a/jstests/core/index_many2.js +++ b/jstests/core/index_many2.js @@ -3,31 +3,44 @@ // @tags: [assumes_no_implicit_index_creation] (function() { +'use strict'; + const t = db.index_many2; t.drop(); -t.save({x: 1}); +assert.commandWorked(t.insert({_id: 1, x: 1})); assert.eq(1, t.getIndexKeys().length, "Expected a single default index."); function make(n) { - var x = {}; + let x = {}; x["x" + n] = 1; return x; } -jsTestLog("Creating 1000 indexes."); +// This should match the constant in IndexCatalogImpl::kMaxNumIndexesAllowed. +const maxNumIndexesAllowed = 64; -// Try to create 1000 indexes. Only 63 will succeed because 64 is the maximum number of indexes -// allowed on a collection. -for (let i = 1; i < 1000; i++) { - // Cannot assert success because only 63 additional indexes will succeed. - t.createIndex(make(i)); -} +jsTestLog("Creating " + (maxNumIndexesAllowed - 1) + " indexes."); + +// Only 63 will succeed because 64 is the maximum number of indexes allowed on a collection. +let i = 1; +assert.soon(() => { + const key = make(i++); + // May fail due to stepdowns and shutdowns. Keep trying until we reach the + // server limit for indexes in a collection. + const res = t.createIndex(key); + const num = t.getIndexKeys().length; + jsTestLog('createIndex: ' + tojson(key) + ': ' + + ' (num indexes: ' + num + '): ' + tojson(res)); + return num === maxNumIndexesAllowed; +}); const indexKeys = t.getIndexKeys(); const num = indexKeys.length; -assert.eq(64, num, "Expected 64 keys, found: " + num); +assert.eq(maxNumIndexesAllowed, num, "Expected 64 keys, found: " + num); + +assert.commandFailedWithCode(t.createIndex({y: 1}), ErrorCodes.CannotCreateIndex); // Drop one of the indexes. const indexToDrop = indexKeys.filter(key => key._id !== 1)[num - 2]; |