From 36d0d2daf79b3b62852ae795e104a74f93e8a9b7 Mon Sep 17 00:00:00 2001 From: Geert Bosch Date: Thu, 5 Nov 2015 14:22:49 -0500 Subject: SERVER-21480: remove race condition in ttl1.js (cherry picked from commit 56943a545ab503b11b747bb40779ab01be58766b) --- jstests/noPassthroughWithMongod/ttl1.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/jstests/noPassthroughWithMongod/ttl1.js b/jstests/noPassthroughWithMongod/ttl1.js index a2d923fc9f5..11469cf2f47 100644 --- a/jstests/noPassthroughWithMongod/ttl1.js +++ b/jstests/noPassthroughWithMongod/ttl1.js @@ -56,10 +56,13 @@ t.ensureIndex( { x : 1 } , { expireAfterSeconds : 20000 } ); assert.soon( function() { return t.count() < 30; - }, "TTL index on x didn't delete" , 70 * 1000 -); + }, "TTL index on x didn't delete" , 70 * 1000); -assert.eq( 0 , t.find( { x : { $lt : new Date( now - 20000000 ) } } ).count() ); +// We know the TTL thread has started deleting. Wait a few seconds to give it a chance to finish. +assert.soon( + function() { + return t.find( { x : { $lt : new Date( now - ( 20000 * 1000 ) ) } } ).count() === 0; + }, "TTL index on x didn't finish deleting", 5 * 1000); assert.eq( 12 , t.count() ); assert.lte( 18, db.serverStatus().metrics.ttl.deletedDocuments ); @@ -71,8 +74,10 @@ t.ensureIndex( { y : 1 } , { expireAfterSeconds : 10000 } ); assert.soon( function() { return t.count() < 12; - }, "TTL index on y didn't delete" , 70 * 1000 -); + }, "TTL index on y didn't delete" , 70 * 1000); -assert.eq( 0 , t.find( { y : { $lt : new Date( now - 10000000 ) } } ).count() ); +assert.soon( + function() { + return t.find( { y : { $lt : new Date( now - ( 10000 * 1000 ) ) } } ).count() === 0; + }, "TTL index on y didn't finish deleting", 5 * 1000); assert.eq( 9 , t.count() ); -- cgit v1.2.1