zacharymorn commented on a change in pull request #1998: URL: https://github.com/apache/lucene-solr/pull/1998#discussion_r509847243
########## File path: lucene/core/src/test/org/apache/lucene/index/TestExitableDirectoryReader.java ########## @@ -163,6 +163,17 @@ public void testExitableFilterTermsIndexReader() throws Exception { searcher.search(query, 10); reader.close(); + // Set a fairly high timeout value (infinite) and expect the query to complete in that time frame. + // Not checking the validity of the result, but checking the sampling kicks in to reduce the number of timeout check + CountingQueryTimeout queryTimeout = new CountingQueryTimeout(); + directoryReader = DirectoryReader.open(directory); + exitableDirectoryReader = new ExitableDirectoryReader(directoryReader, queryTimeout); + reader = new TestReader(getOnlyLeafReader(exitableDirectoryReader)); + searcher = new IndexSearcher(reader); + searcher.search(query, 10); + reader.close(); + assertEquals(3, queryTimeout.getShouldExitCallCount()); Review comment: > Because 3 TermsEnum are created: it is a PrefixQuery and there is one TermsEnum created for AutomatonQuery.intersect() (the next call timeout check is skipped once), then 2 TermsEnum created for the 2 matching terms "one" and "ones"). Yes this is exactly what happened. Without the check the call count will be 4. ------ I've tried to come up with a new test like what you suggested: ``` /** * Tests time out check sampling of TermsEnum iterations * @throws Exception on error */ public void testExitableTermsEnumSampleTimeoutCheck() throws Exception { try(Directory directory = newDirectory()) { try(IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(new MockAnalyzer(random())))) { for(int i = 0; i < 50; i++) { Document d1 = new Document(); d1.add(newTextField("default", "term" + i, Field.Store.YES)); writer.addDocument(d1); } writer.forceMerge(1); writer.commit(); DirectoryReader directoryReader; DirectoryReader exitableDirectoryReader; IndexReader reader; IndexSearcher searcher; Query query = new PrefixQuery(new Term("default", "term")); // Set a fairly high timeout value (infinite) and expect the query to complete in that time frame. // Not checking the validity of the result, but checking the sampling kicks in to reduce the number of timeout check CountingQueryTimeout queryTimeout = new CountingQueryTimeout(); directoryReader = DirectoryReader.open(directory); exitableDirectoryReader = new ExitableDirectoryReader(directoryReader, queryTimeout); reader = new TestReader(getOnlyLeafReader(exitableDirectoryReader)); searcher = new IndexSearcher(reader); searcher.search(query, 300); reader.close(); assertEquals(54, queryTimeout.getShouldExitCallCount()); } } } ``` This test actually failed as the actual call count is 5 instead of 54. After some debugging it turns out that the threshold setting here https://github.com/apache/lucene-solr/blob/67ecd8ff9ad3640016424ded86bfaaadd815b96d/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryConstantScoreWrapper.java#L118 also help reduce the query timeout check call count. If I were to change the threshold to 100, then the test will pass. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org