Skip to content

Commit f3a58b6

Browse files
authored
ESQL: Fix limit task test (#117270) (#117378)
Fix a test for the task results when running the `LIMIT` operation. We were releasing a few permits to get the query started. And when you combine that with the page worth of permits that the test was releasing we'd sometimes finish the entire limited query, stopping the task too early to find a running task. Closes #107293
1 parent 5b220dd commit f3a58b6

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/EsqlActionTaskIT.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ public class EsqlActionTaskIT extends AbstractPausableIntegTestCase {
7979
private String REDUCE_DESCRIPTION;
8080
private boolean nodeLevelReduction;
8181

82+
/**
83+
* Number of docs released by {@link #startEsql}.
84+
*/
85+
private int prereleasedDocs;
86+
8287
@Before
8388
public void setup() {
8489
assumeTrue("requires query pragmas", canUseQueryPragmas());
@@ -104,6 +109,7 @@ public void testTaskContents() throws Exception {
104109
ActionFuture<EsqlQueryResponse> response = startEsql();
105110
try {
106111
getTasksStarting();
112+
logger.info("unblocking script");
107113
scriptPermits.release(pageSize());
108114
List<TaskInfo> foundTasks = getTasksRunning();
109115
int luceneSources = 0;
@@ -216,9 +222,15 @@ private ActionFuture<EsqlQueryResponse> startEsql() {
216222
return startEsql("from test | stats sum(pause_me)");
217223
}
218224

225+
/**
226+
* Start an ESQL query, releasing a few docs from the {@code pause_me}
227+
* script so it'll actually start but won't finish it's first page.
228+
*/
219229
private ActionFuture<EsqlQueryResponse> startEsql(String query) {
220230
scriptPermits.drainPermits();
221-
scriptPermits.release(between(1, 5));
231+
// Allow a few docs to calculate os the query gets "started"
232+
prereleasedDocs = between(1, pageSize() / 2);
233+
scriptPermits.release(prereleasedDocs);
222234
var settingsBuilder = Settings.builder()
223235
// Force shard partitioning because that's all the tests know how to match. It is easier to reason about too.
224236
.put("data_partitioning", "shard")
@@ -456,6 +468,7 @@ public void testTaskContentsForTopNQuery() throws Exception {
456468
ActionFuture<EsqlQueryResponse> response = startEsql("from test | sort pause_me | keep pause_me");
457469
try {
458470
getTasksStarting();
471+
logger.info("unblocking script");
459472
scriptPermits.release(pageSize());
460473
getTasksRunning();
461474
} finally {
@@ -467,7 +480,6 @@ public void testTaskContentsForTopNQuery() throws Exception {
467480
}
468481
}
469482

470-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/107293")
471483
public void testTaskContentsForLimitQuery() throws Exception {
472484
String limit = Integer.toString(randomIntBetween(pageSize() + 1, 2 * numberOfDocs()));
473485
READ_DESCRIPTION = """
@@ -487,7 +499,8 @@ public void testTaskContentsForLimitQuery() throws Exception {
487499
ActionFuture<EsqlQueryResponse> response = startEsql("from test | keep pause_me | limit " + limit);
488500
try {
489501
getTasksStarting();
490-
scriptPermits.release(pageSize());
502+
logger.info("unblocking script");
503+
scriptPermits.release(pageSize() - prereleasedDocs);
491504
getTasksRunning();
492505
} finally {
493506
scriptPermits.release(numberOfDocs());
@@ -516,6 +529,7 @@ public void testTaskContentsForGroupingStatsQuery() throws Exception {
516529
ActionFuture<EsqlQueryResponse> response = startEsql("from test | stats max(foo) by pause_me");
517530
try {
518531
getTasksStarting();
532+
logger.info("unblocking script");
519533
scriptPermits.release(pageSize());
520534
getTasksRunning();
521535
} finally {

0 commit comments

Comments
 (0)