Skip to content

Commit

Permalink
Use CDL to block threads to avoid flaky tests. (#14116)
Browse files Browse the repository at this point in the history
* Use CDL to block threads to avoid flaky tests.

* Update CHANGES.txt
  • Loading branch information
aoli-al authored Jan 9, 2025
1 parent 2756cd9 commit ee65e8f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ Bug Fixes

Other
---------------------

* GITHUB#14081: Fix urls describing why NIOFS is not recommended for Windows (Marcel Yeonghyeon Ko)

* GITHUB#14116 Use CDL to block threads to avoid flaky tests. (Ao Li)

======================= Lucene 10.1.0 =======================

API Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ protected void doMerge(MergeSource mergeSource, MergePolicy.OneMerge merge)
dir.close();
}

@SuppressForbidden(reason = "Thread sleep")
public void testIntraMergeThreadPoolIsLimitedByMaxThreads() throws IOException {
ConcurrentMergeScheduler mergeScheduler = new ConcurrentMergeScheduler();
MergeScheduler.MergeSource mergeSource =
Expand Down Expand Up @@ -475,11 +474,12 @@ public void merge(MergePolicy.OneMerge merge) throws IOException {
Executor executor = mergeScheduler.intraMergeExecutor;
AtomicInteger threadsExecutedOnPool = new AtomicInteger();
AtomicInteger threadsExecutedOnSelf = new AtomicInteger();
for (int i = 0; i < 4; i++) {
CountDownLatch latch = new CountDownLatch(1);
final int totalThreads = 4;
for (int i = 0; i < totalThreads; i++) {
mergeScheduler.mergeThreads.add(
mergeScheduler.new MergeThread(mergeSource, merge) {
@Override
@SuppressForbidden(reason = "Thread sleep")
public void run() {
executor.execute(
() -> {
Expand All @@ -489,7 +489,7 @@ public void run() {
threadsExecutedOnPool.incrementAndGet();
}
try {
Thread.sleep(100);
latch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
Expand All @@ -500,6 +500,10 @@ public void run() {
for (ConcurrentMergeScheduler.MergeThread thread : mergeScheduler.mergeThreads) {
thread.start();
}
while (threadsExecutedOnSelf.get() + threadsExecutedOnPool.get() < totalThreads) {
Thread.yield();
}
latch.countDown();
mergeScheduler.sync();
assertEquals(3, threadsExecutedOnSelf.get());
assertEquals(1, threadsExecutedOnPool.get());
Expand Down

0 comments on commit ee65e8f

Please sign in to comment.