0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 01:21:03 +01:00
mongodb/jstests/core/compact_keeps_indexes.js
Max Hirschhorn 9ad8d6335f SERVER-40076 Tag JS tests with reason they're unable to run in Atlas.
There are likely more JavaScript tests which have been added since
r3.6.9 that still need to be tagged.

(cherry picked from commit 05ec08fa62)
2019-03-11 18:17:29 -04:00

47 lines
1.3 KiB
JavaScript

// SERVER-16676 Make sure compact doesn't leave the collection with bad indexes
// SERVER-16967 Make sure compact doesn't crash while collections are being dropped
// in a different database.
// @tags: [
// # compact command is not available on embedded
// incompatible_with_embedded,
// uses_multiple_connections,
// ]
(function() {
'use strict';
var coll = db.compact_keeps_indexes;
coll.drop();
coll.insert({_id: 1, x: 1});
coll.ensureIndex({x: 1});
assert.eq(coll.getIndexes().length, 2);
// force:true is for replset passthroughs
var res = coll.runCommand('compact', {force: true});
// Some storage engines (for example, inMemoryExperiment) do not support the compact command.
if (res.code == 115) { // CommandNotSupported
return;
}
assert.commandWorked(res);
assert.eq(coll.getIndexes().length, 2);
assert.eq(coll.find({_id: 1}).itcount(), 1);
assert.eq(coll.find({x: 1}).itcount(), 1);
var dropCollectionShell = startParallelShell(function() {
var t = db.getSiblingDB('test_compact_keeps_indexes_drop').testcoll;
t.drop();
for (var i = 0; i < 100; i++) {
t.save({a: 1});
t.drop();
}
});
for (var i = 0; i < 10; i++) {
coll.runCommand('compact');
}
dropCollectionShell();
}());