2015-05-01 03:16:12 +02:00
|
|
|
// Test that the TTL monitor will correctly use TTL indexes that are also partial indexes.
|
|
|
|
// SERVER-17984.
|
2015-04-28 22:47:40 +02:00
|
|
|
(function() {
|
|
|
|
"use strict";
|
|
|
|
// Launch mongod with shorter TTL monitor sleep interval.
|
|
|
|
var runner = MongoRunner.runMongod({setParameter: "ttlMonitorSleepSecs=1"});
|
|
|
|
var coll = runner.getDB("test").ttl_partial_index;
|
|
|
|
coll.drop();
|
|
|
|
|
|
|
|
// Create TTL partial index.
|
2016-03-09 18:17:50 +01:00
|
|
|
assert.commandWorked(coll.ensureIndex(
|
|
|
|
{x: 1}, {expireAfterSeconds: 0, partialFilterExpression: {z: {$exists: true}}}));
|
2015-04-28 22:47:40 +02:00
|
|
|
|
2015-05-01 03:16:12 +02:00
|
|
|
var now = new Date();
|
2015-04-28 22:47:40 +02:00
|
|
|
assert.writeOK(coll.insert({x: now, z: 2}));
|
|
|
|
assert.writeOK(coll.insert({x: now}));
|
|
|
|
|
2015-05-01 03:16:12 +02:00
|
|
|
// Wait for the TTL monitor to run at least twice (in case we weren't finished setting up our
|
|
|
|
// collection when it ran the first time).
|
2015-04-28 22:47:40 +02:00
|
|
|
var ttlPass = coll.getDB().serverStatus().metrics.ttl.passes;
|
|
|
|
assert.soon(function() {
|
2016-03-09 18:17:50 +01:00
|
|
|
return coll.getDB().serverStatus().metrics.ttl.passes >= ttlPass + 2;
|
|
|
|
}, "TTL monitor didn't run before timing out.");
|
2015-04-28 22:47:40 +02:00
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
assert.eq(0,
|
|
|
|
coll.find({z: {$exists: true}}).hint({x: 1}).itcount(),
|
2015-04-28 22:47:40 +02:00
|
|
|
"Wrong number of documents in partial index, after TTL monitor run");
|
2016-03-09 18:17:50 +01:00
|
|
|
assert.eq(
|
|
|
|
1, coll.find().itcount(), "Wrong number of documents in collection, after TTL monitor run");
|
2015-04-28 22:47:40 +02:00
|
|
|
})();
|