@@ -186,14 +186,15 @@ class QueryBatchCursorFunctionalSpecification extends OperationFunctionalSpecifi
186186
187187 @SuppressWarnings (' EmptyCatchBlock' )
188188 @Category (Slow )
189- def ' test tailable' () {
189+ def ' should block waiting for next batch on a tailable cursor' () {
190+ given :
191+ def connection = connectionSource. getConnection()
190192 collectionHelper. create(collectionName, new CreateCollectionOptions (). capped(true ). sizeInBytes(1000 ))
191193 collectionHelper. insertDocuments(new DocumentCodec (), new Document (' _id' , 1 ). append(' ts' , new BsonTimestamp (5 , 0 )))
192- def firstBatch = executeQuery(new BsonDocument (' ts' , new BsonDocument (' $gte' , new BsonTimestamp (5 , 0 ))), 0 , 2 , true , true );
193-
194+ def firstBatch = executeQuery(new BsonDocument (' ts' , new BsonDocument (' $gte' , new BsonTimestamp (5 , 0 ))), 0 , 2 , true , awaitData);
194195
195196 when :
196- cursor = new QueryBatchCursor<Document > (firstBatch, 0 , 2 , new DocumentCodec (), connectionSource)
197+ cursor = new QueryBatchCursor<Document > (firstBatch, 0 , 2 , maxTimeMS, new DocumentCodec (), connectionSource, connection )
197198
198199 then :
199200 cursor. hasNext()
@@ -203,7 +204,7 @@ class QueryBatchCursorFunctionalSpecification extends OperationFunctionalSpecifi
203204 def latch = new CountDownLatch (1 )
204205 Thread . start {
205206 try {
206- sleep(1000 )
207+ sleep(500 )
207208 collectionHelper. insertDocuments(new DocumentCodec (), new Document (' _id' , 2 ). append(' ts' , new BsonTimestamp (6 , 0 )))
208209 } catch (interrupt) {
209210 // pass
@@ -223,6 +224,13 @@ class QueryBatchCursorFunctionalSpecification extends OperationFunctionalSpecifi
223224 if (! cleanedUp) {
224225 throw new MongoTimeoutException (' Timed out waiting for documents to be inserted' )
225226 }
227+ connection?. release()
228+
229+ where :
230+ awaitData | maxTimeMS
231+ true | 0
232+ true | 100
233+ false | 0
226234 }
227235
228236 @Category (Slow )
0 commit comments