Skip to content

Apache Lucene open-source search software

LUCENE-8275: Fix BaseLockFactoryTestCase to step out on Windowns if pending files are found

Simon Willnauer933d8a6995c0
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOutOfFileDescriptors.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOutOfFileDescriptors.java
index 290e051a7f9..2d2ce8fd182 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOutOfFileDescriptors.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterOutOfFileDescriptors.java
@@ -25,6 +25,7 @@ import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.MockDirectoryWrapper;
+import org.apache.lucene.util.Constants;
import org.apache.lucene.util.LineFileDocs;
import org.apache.lucene.util.LuceneTestCase.SuppressFileSystems;
import org.apache.lucene.util.LuceneTestCase;
@@ -65,6 +66,10 @@ public class TestIndexWriterOutOfFileDescriptors extends LuceneTestCase {
if (ms instanceof ConcurrentMergeScheduler) {
((ConcurrentMergeScheduler) ms).setSuppressExceptions();
}
+ if (Constants.WINDOWS && dir.checkPendingDeletions()) {
+ // if we are on windows and we have pending deletions we can't execute this test
+ break;
+ }
w = new IndexWriter(dir, iwc);
if (r != null && random().nextInt(5) == 3) {
if (random().nextBoolean()) {
diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/BaseLockFactoryTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/store/BaseLockFactoryTestCase.java
index 312b644e9f5..12f2204017d 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/store/BaseLockFactoryTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/store/BaseLockFactoryTestCase.java
@@ -172,11 +172,10 @@ public abstract class BaseLockFactoryTestCase extends LuceneTestCase {
SearcherThread searcher = new SearcherThread(100, dir);
writer.start();
searcher.start();
-
- while(writer.isAlive() || searcher.isAlive()) {
- Thread.sleep(1000);
- }
-
+
+ writer.join();
+ searcher.join();
+
assertTrue("IndexWriter hit unexpected exceptions", !writer.hitException);
assertTrue("IndexSearcher hit unexpected exceptions", !searcher.hitException);
@@ -232,14 +231,20 @@ public abstract class BaseLockFactoryTestCase extends LuceneTestCase {
printStream.println("\nTEST: WriterThread iter=" + i);
iwc.setOpenMode(OpenMode.APPEND);
try {
+ if (Constants.WINDOWS && dir.checkPendingDeletions()) {
+ // on windows we can potentially have pending deletes here if this happens we step out like in the catch clause
+ // tests using this also assumes no mock window FS
+ break;
+ }
writer = new IndexWriter(dir, iwc);
+
} catch (Throwable t) {
if (Constants.WINDOWS && t instanceof AccessDeniedException) {
// LUCENE-6684: suppress this: on Windows, a file in the curious "pending delete" state can
// cause this exc on IW init, where one thread/process deleted an old
// segments_N, but the delete hasn't finished yet because other threads/processes
// still have it open
- printStream.println("TEST: AccessDeniedException on init witer");
+ printStream.println("TEST: AccessDeniedException on init writer");
t.printStackTrace(printStream);
} else {
hitException = true;
@@ -268,7 +273,6 @@ public abstract class BaseLockFactoryTestCase extends LuceneTestCase {
System.out.println(toString(baos));
break;
}
- writer = null;
}
}
}