Skip to content

Commit af2aebd

Browse files
authored
Wait for async actions in testSimpleFinishClose (#138447)
Partial backport of #128162 to wait for async actions in tests. Closes #136389
1 parent 62631f8 commit af2aebd

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

x-pack/plugin/esql/compute/test/src/main/java/org/elasticsearch/compute/test/OperatorTestCase.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.elasticsearch.compute.data.Block;
2424
import org.elasticsearch.compute.data.BlockFactory;
2525
import org.elasticsearch.compute.data.Page;
26+
import org.elasticsearch.compute.operator.AsyncOperator;
2627
import org.elasticsearch.compute.operator.Driver;
2728
import org.elasticsearch.compute.operator.DriverContext;
2829
import org.elasticsearch.compute.operator.DriverRunner;
@@ -247,11 +248,23 @@ public void testSimpleFinishClose() throws Exception {
247248
assert input.size() == 1 : "Expected single page, got: " + input;
248249
// eventually, when driverContext always returns a tracking factory, we can enable this assertion
249250
// assertThat(driverContext.blockFactory().breaker().getUsed(), greaterThan(0L));
250-
Page page = input.get(0);
251251
try (var operator = simple().get(driverContext)) {
252252
assert operator.needsInput();
253-
operator.addInput(page);
253+
for (Page page : input) {
254+
if (operator.needsInput()) {
255+
operator.addInput(page);
256+
} else {
257+
page.releaseBlocks();
258+
}
259+
}
254260
operator.finish();
261+
// for async operator, we need to wait for async actions to finish.
262+
if (operator instanceof AsyncOperator<?> || randomBoolean()) {
263+
driverContext.finish();
264+
PlainActionFuture<Void> waitForAsync = new PlainActionFuture<>();
265+
driverContext.waitForAsyncActions(waitForAsync);
266+
waitForAsync.actionGet(TimeValue.timeValueSeconds(30));
267+
}
255268
}
256269
}
257270

0 commit comments

Comments
 (0)