stefanvodita commented on code in PR #12756: URL: https://github.com/apache/lucene/pull/12756#discussion_r1402701132
########## lucene/core/src/test/org/apache/lucene/search/TestIndexSearcher.java: ########## @@ -293,4 +298,218 @@ public void testNullExecutorNonNullTaskExecutor() { IndexSearcher indexSearcher = new IndexSearcher(reader); assertNotNull(indexSearcher.getTaskExecutor()); } + + /* + * The goal of this test is to ensure that when multiple concurrent slices are + * being searched, and one of the concurrent tasks throws an Exception, the other + * tasks become aware of it (via the ExceptionBasedQueryTimeout in IndexSearcher) + * and exit immediately rather than completing their search actions. + * + * To test this: + * - a concurrent Executor is used to ensure concurrent tasks are running + * - the MatchAllOrThrowExceptionQuery is used to ensure that one of the search + * tasks throws an Exception + * - a testing ExceptionBasedTimeoutWrapper is used to track the number of times + * and early exit happens + * - a CountDownLatch is used to synchronize the task that is going to throw an Exception + * with another task that is in the ExceptionBasedQueryTimeout.shouldExit method, + * ensuring the Exception is thrown while at least one other task is still running + * - a second CountDownLatch is used to synchronize between the + * ExceptionBasedQueryTimeout.notifyExceptionThrown call (coming from the task thread + * where the exception is thrown) and the ExceptionBasedQueryTimeout.shouldExit method + * to ensure that at least one task has shouldExit return true (for an early exit) + * - an atomic earlyExitCounter tracks how many tasks exited early due to + * TimeLimitingBulkScorer.TimeExceededException in the TimeLimitingBulkScorer + */ + public void testMultipleSegmentsWithExceptionCausesEarlyTerminationOfRunningTasks() { + // skip this test when only one leaf, since one leaf means one task + // and the TimeLimitingBulkScorer will NOT be added in IndexSearcher + if (reader.leaves().size() <= 1) { Review Comment: There are other tests which create their own index. Is it worth doing that just to avoid this case? I'm not sure. -- 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. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org 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