Skip to content

Commit a8888ca

Browse files
authored
test: fix some slow tests (#15323)
Especially tests that ran very slow on windows or macos
1 parent aa4f143 commit a8888ca

32 files changed

+80
-71
lines changed

lucene/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/TestWordDelimiterGraphFilter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,9 +1104,10 @@ public void testToDot() throws Exception {
11041104

11051105
private String randomWDFText() {
11061106
StringBuilder b = new StringBuilder();
1107-
int length = TestUtil.nextInt(random(), 1, 50);
1107+
Random random = random();
1108+
int length = TestUtil.nextInt(random, 1, 20);
11081109
for (int i = 0; i < length; i++) {
1109-
int surpriseMe = random().nextInt(37);
1110+
int surpriseMe = random.nextInt(37);
11101111
int lower = -1;
11111112
int upper = -1;
11121113
if (surpriseMe < 10) {
@@ -1130,7 +1131,7 @@ private String randomWDFText() {
11301131
}
11311132

11321133
if (lower != -1) {
1133-
b.append((char) TestUtil.nextInt(random(), lower, upper));
1134+
b.append((char) TestUtil.nextInt(random, lower, upper));
11341135
}
11351136
}
11361137

@@ -1146,7 +1147,7 @@ public void testInvalidFlag() throws Exception {
11461147
}
11471148

11481149
public void testRandomPaths() throws Exception {
1149-
int iters = atLeast(10);
1150+
int iters = atLeast(1);
11501151
for (int iter = 0; iter < iters; iter++) {
11511152
String text = randomWDFText();
11521153
if (VERBOSE) {

lucene/core/src/java/org/apache/lucene/util/OfflineSorter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ private BufferSize(long bytes) {
9797
this.bytes = (int) bytes;
9898
}
9999

100+
// internal for testing
101+
static BufferSize kilobytes(long kb) {
102+
return new BufferSize(kb * 1024);
103+
}
104+
100105
/** Creates a {@link BufferSize} in MB. The given values must be &gt; 0 and &lt; 2048. */
101106
public static BufferSize megabytes(long mb) {
102107
return new BufferSize(mb * MB);

lucene/core/src/test/org/apache/lucene/codecs/lucene103/blocktree/TestTrie.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void testVeryLongTerms() throws Exception {
6767
public void testOneByteTerms() throws Exception {
6868
// heavily test single byte terms to generate various label distribution.
6969
Supplier<byte[]> supplier = () -> new byte[] {(byte) random().nextInt()};
70-
int round = atLeast(50);
70+
int round = atLeast(5);
7171
for (int i = 0; i < round; i++) {
7272
testTrieLookup(supplier, 10);
7373
}

lucene/core/src/test/org/apache/lucene/document/TestLatLonPointDistanceFeatureQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ public void testCompareSorting() throws IOException {
455455
LatLonDocValuesField docValue = new LatLonDocValuesField("foo", 0., 0.);
456456
doc.add(docValue);
457457

458-
int numDocs = atLeast(10000);
458+
int numDocs = atLeast(2048);
459459
for (int i = 0; i < numDocs; ++i) {
460460
double lat = random().nextDouble() * 180 - 90;
461461
double lon = random().nextDouble() * 360 - 180;

lucene/core/src/test/org/apache/lucene/index/TestIndexSorting.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3333,7 +3333,7 @@ public void testMixRandomDocumentsWithBlocks() throws IOException {
33333333
iwc.setIndexSort(indexSort);
33343334
iwc.setParentField(parentField);
33353335
RandomIndexWriter randomIndexWriter = new RandomIndexWriter(random(), dir, iwc);
3336-
int numDocs = random().nextInt(100, 1000);
3336+
int numDocs = random().nextInt(100, 300);
33373337
for (int i = 0; i < numDocs; i++) {
33383338
if (rarely()) {
33393339
randomIndexWriter.deleteDocuments(new Term("id", "" + random().nextInt(0, i + 1)));

lucene/core/src/test/org/apache/lucene/index/TestIndexTooManyDocs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void testIndexTooManyDocs() throws IOException, InterruptedException {
4343
IndexWriter writer = new IndexWriter(dir, config);
4444
try {
4545
IndexWriter.setMaxDocs(numMaxDoc);
46-
int numThreads = 5 + random().nextInt(5);
46+
int numThreads = atLeast(2);
4747
Thread[] threads = new Thread[numThreads];
4848
CountDownLatch latch = new CountDownLatch(numThreads);
4949
CountDownLatch indexingDone = new CountDownLatch(numThreads - 2);

lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,8 +1098,8 @@ public void testThreadInterruptDeadlock() throws Exception {
10981098
new ThreadInterruptedException(new InterruptedException()).getCause()
10991099
instanceof InterruptedException);
11001100

1101-
// issue 100 interrupts to child thread
1102-
final int numInterrupts = atLeast(100);
1101+
// issue 20 interrupts to child thread
1102+
final int numInterrupts = atLeast(20);
11031103
int i = 0;
11041104
while (i < numInterrupts) {
11051105
// TODO: would be nice to also sometimes interrupt the CMS merge threads too ...
@@ -4388,9 +4388,9 @@ public void testMaxCompletedSequenceNumber() throws IOException, InterruptedExce
43884388
SearcherManager manager = new SearcherManager(writer, new SearcherFactory())) {
43894389
CountDownLatch start = new CountDownLatch(1);
43904390
int numDocs =
4391-
TEST_NIGHTLY ? TestUtil.nextInt(random(), 100, 600) : TestUtil.nextInt(random(), 10, 60);
4391+
TEST_NIGHTLY ? TestUtil.nextInt(random(), 100, 600) : TestUtil.nextInt(random(), 10, 30);
43924392
AtomicLong maxCompletedSeqID = new AtomicLong(-1);
4393-
Thread[] threads = new Thread[2 + random().nextInt(2)];
4393+
Thread[] threads = new Thread[2];
43944394
for (int i = 0; i < threads.length; i++) {
43954395
int idx = i;
43964396
threads[i] =

lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected TokenStreamComponents createComponents(String fieldName) {
101101
conf.setMergeScheduler(new SerialMergeScheduler());
102102
conf.setCodec(codec);
103103

104-
int numDocs = atLeast(100);
104+
int numDocs = atLeast(20);
105105

106106
IndexWriter iw = new IndexWriter(dir, conf);
107107
try {

lucene/core/src/test/org/apache/lucene/index/TestIndexWriterNRTIsCurrent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void testIsCurrentWithThreads() throws IOException, InterruptedException
4343
int numReaderThreads = TEST_NIGHTLY ? TestUtil.nextInt(random(), 2, 5) : 2;
4444
ReaderThread[] threads = new ReaderThread[numReaderThreads];
4545
final CountDownLatch latch = new CountDownLatch(1);
46-
WriterThread writerThread = new WriterThread(holder, writer, atLeast(500), random(), latch);
46+
WriterThread writerThread = new WriterThread(holder, writer, atLeast(200), random(), latch);
4747
for (int i = 0; i < threads.length; i++) {
4848
threads[i] = new ReaderThread(holder, latch);
4949
threads[i].start();
@@ -110,7 +110,7 @@ public void run() {
110110
latch.countDown();
111111
}
112112
}
113-
if (random.nextBoolean()) {
113+
if (random.nextInt(7) == 0) {
114114
writer.commit();
115115
final DirectoryReader newReader = DirectoryReader.openIfChanged(currentReader);
116116
if (newReader != null) {

lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public IndexSearcher newSearcher(IndexReader reader, IndexReader previous)
127127
final SearcherManager mgr = new SearcherManager(w.w, applyDeletes, false, searcherFactory);
128128
final AtomicBoolean indexing = new AtomicBoolean(true);
129129
final AtomicReference<Throwable> error = new AtomicReference<>();
130-
final int numDocs = atLeast(1000);
130+
final int numDocs = atLeast(257);
131131
Thread[] threads = new Thread[3];
132132
threads[0] =
133133
new Thread() {

0 commit comments

Comments
 (0)