summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTess Avitabile <tess.avitabile@mongodb.com>2017-03-01 11:09:47 -0500
committerTess Avitabile <tess.avitabile@mongodb.com>2017-03-02 14:57:23 -0500
commit4c71a22acbb34c95b1a6e4a9d433983d684f37c3 (patch)
tree9987716b9ff8a9ad3bb42aa3aff1220a8b8999c6
parent23a00d8dcabb90734a122fd2d15d29327f8812f7 (diff)
downloadmongo-4c71a22acbb34c95b1a6e4a9d433983d684f37c3.tar.gz
SERVER-28154 Remove race condition in ttl_sharded.js
(cherry picked from commit cb2fdf468435d7a5c7582069d4026f1d4e935755)
-rw-r--r--jstests/noPassthroughWithMongod/ttl_sharded.js30
1 files changed, 16 insertions, 14 deletions
diff --git a/jstests/noPassthroughWithMongod/ttl_sharded.js b/jstests/noPassthroughWithMongod/ttl_sharded.js
index d6896665b65..4d837303b27 100644
--- a/jstests/noPassthroughWithMongod/ttl_sharded.js
+++ b/jstests/noPassthroughWithMongod/ttl_sharded.js
@@ -36,15 +36,14 @@ t.ensureIndex({x: 1}, {expireAfterSeconds: 20000});
s.adminCommand({split: ns, middle: {_id: 12}});
s.adminCommand({moveChunk: ns, find: {_id: 0}, to: s.getOther(s.getPrimaryShard(dbname)).name});
-// one shard will lose 12/12 docs, the other 6/12, so count will go
-// from 24 -> 18 or 12 -> 6
-assert.soon(function() {
- return t.count() < 7;
-}, "TTL index on x didn't delete enough", 70 * 1000);
-
-// ensure that count ultimately ends up at 6
-assert.eq(0, t.find({x: {$lt: new Date(now - 20000000)}}).count());
-assert.eq(6, t.count());
+// Check that all expired documents are deleted.
+assert.soon(
+ function() {
+ return t.count() === 6 && t.find({x: {$lt: new Date(now - 20000000)}}).count() === 0;
+ },
+ "TTL index did not successfully delete expired documents, all documents: " +
+ tojson(t.find().toArray()),
+ 70 * 1000);
// now lets check things explicily on each shard
var shard0 = s._connections[0].getDB(dbname);
@@ -73,10 +72,13 @@ s.getDB(dbname).runCommand({collMod: coll, index: {keyPattern: {x: 1}, expireAft
assert.eq(10000, getTTLTime(shard0.getCollection(coll), {x: 1}));
assert.eq(10000, getTTLTime(shard1.getCollection(coll), {x: 1}));
-assert.soon(function() {
- return t.count() < 6;
-}, "new expireAfterSeconds value not taking effect", 70 * 1000);
-assert.eq(0, t.find({x: {$lt: new Date(now - 10000000)}}).count());
-assert.eq(3, t.count());
+// Check that all expired documents are deleted.
+assert.soon(
+ function() {
+ return t.count() === 3 && t.find({x: {$lt: new Date(now - 10000000)}}).count() === 0;
+ },
+ "new expireAfterSeconds did not successfully delete expired documents, all documents: " +
+ tojson(t.find().toArray()),
+ 70 * 1000);
s.stop();