Skip to content

Commit 4b882f7

Browse files
committed
[test](fe) Synchronize split producer cancellation completion
### What problem does this PR solve? Issue Number: None Related PR: #69298 Problem Summary: The active-read cancellation test for external-file split planning waited for the source-close latch and then immediately required the producer completion counter to be one. SplitProducer closes the source before invoking its completion callback, so the test can legitimately observe zero completions and fail FE CI. Hold the test read active across cancellation, force a controlled close/completion gap, and wait for a callback-completed latch before checking terminal counts. This deterministically verifies exactly one close and one completion without depending on thread scheduling. ### Release note None ### Check List (For Author) - Test: Unit Test - Reproduced the exact CI assertion failure with a deterministic close barrier before fixing the completion wait. - All 62 related FE tests pass: SplitProducerTest, SplitAssignmentTest, SplitSourceTest, HiveStreamingSplitTest and FairTaskExecutorTest. - Full FE packaging and Checkstyle pass through build.sh --fe -j4 (UI build disabled). - Behavior changed: No (test synchronization only) - Does this need documentation: No
1 parent dcd5576 commit 4b882f7

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

‎fe/fe-core/src/test/java/org/apache/doris/datasource/SplitProducerTest.java‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import com.google.common.collect.LinkedListMultimap;
2828
import com.google.common.collect.Multimap;
29+
import com.google.common.util.concurrent.Uninterruptibles;
2930
import org.junit.jupiter.api.Assertions;
3031
import org.junit.jupiter.api.Test;
3132
import org.mockito.Mockito;
@@ -164,18 +165,22 @@ void cancellationDoesNotCloseTheSourceDuringAnActiveRead() throws Exception {
164165
Fixture fixture = new Fixture(1, 1);
165166
CountDownLatch reading = new CountDownLatch(1);
166167
CountDownLatch release = new CountDownLatch(1);
168+
CountDownLatch finishClose = new CountDownLatch(1);
167169
RecordingSource source = new RecordingSource(1, 0) {
168170
@Override
169171
public List<Split> getNextBatch() throws IOException {
170172
reading.countDown();
171-
try {
172-
Assertions.assertTrue(release.await(5, TimeUnit.SECONDS));
173-
} catch (InterruptedException e) {
174-
Thread.currentThread().interrupt();
175-
throw new IOException(e);
176-
}
173+
// Keep the read active until the test explicitly releases it, even after cancellation.
174+
Assertions.assertTrue(Uninterruptibles.awaitUninterruptibly(release, 5, TimeUnit.SECONDS));
177175
return super.getNextBatch();
178176
}
177+
178+
@Override
179+
public void close() {
180+
super.close();
181+
// source.closed signals close entry, before the producer invokes its completion callback.
182+
Assertions.assertTrue(Uninterruptibles.awaitUninterruptibly(finishClose, 5, TimeUnit.SECONDS));
183+
}
179184
};
180185
ExecutorService executor = Executors.newFixedThreadPool(2);
181186
try {
@@ -185,10 +190,14 @@ public List<Split> getNextBatch() throws IOException {
185190
Assertions.assertEquals(0, source.closeCalls.get());
186191
release.countDown();
187192
Assertions.assertTrue(source.closed.await(5, TimeUnit.SECONDS));
193+
Assertions.assertEquals(0, fixture.completions.get());
194+
finishClose.countDown();
195+
Assertions.assertTrue(fixture.completed.await(5, TimeUnit.SECONDS));
188196
Assertions.assertEquals(1, source.closeCalls.get());
189197
Assertions.assertEquals(1, fixture.completions.get());
190198
} finally {
191199
release.countDown();
200+
finishClose.countDown();
192201
executor.shutdownNow();
193202
Assertions.assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS));
194203
}
@@ -375,6 +384,7 @@ private static class Fixture {
375384
final SplitGenerator generator = Mockito.mock(SplitGenerator.class);
376385
final FederationBackendPolicy policy = Mockito.mock(FederationBackendPolicy.class);
377386
final AtomicInteger completions = new AtomicInteger();
387+
final CountDownLatch completed = new CountDownLatch(1);
378388
final Map<Long, Integer> conversions = new HashMap<>();
379389
SplitAssignment assignment;
380390

@@ -400,6 +410,7 @@ void start(Executor executor, RecordingSource source) {
400410
}
401411
completions.incrementAndGet();
402412
assignment.finishSchedule();
413+
completed.countDown();
403414
}).start();
404415
}
405416

0 commit comments

Comments
 (0)