Skip to content

Commit 88e806b

Browse files
committed
Aggs: Fix Filters agg cancellation flaky test
1 parent 3025f6c commit 88e806b

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/bucket/FiltersCancellationIT.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.elasticsearch.test.ESIntegTestCase;
2929
import org.elasticsearch.xcontent.XContentBuilder;
3030
import org.elasticsearch.xcontent.json.JsonXContent;
31+
import org.junit.Before;
3132

3233
import java.util.Collection;
3334
import java.util.List;
@@ -39,6 +40,7 @@
3940
import static org.elasticsearch.search.aggregations.AggregationBuilders.filters;
4041
import static org.elasticsearch.search.aggregations.AggregationBuilders.terms;
4142
import static org.hamcrest.Matchers.empty;
43+
import static org.hamcrest.Matchers.equalTo;
4244
import static org.hamcrest.Matchers.greaterThan;
4345
import static org.hamcrest.Matchers.not;
4446

@@ -55,11 +57,12 @@ public class FiltersCancellationIT extends ESIntegTestCase {
5557

5658
@Override
5759
protected Collection<Class<? extends Plugin>> nodePlugins() {
58-
return CollectionUtils.appendToCopy(super.nodePlugins(), pausableFieldPluginClass());
60+
return CollectionUtils.appendToCopy(super.nodePlugins(), PauseScriptPlugin.class);
5961
}
6062

61-
protected Class<? extends Plugin> pausableFieldPluginClass() {
62-
return PauseScriptPlugin.class;
63+
@Override
64+
public Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
65+
return Settings.builder().put(super.nodeSettings(nodeOrdinal, otherSettings)).put("thread_pool.search.size", 4).build();
6366
}
6467

6568
@Override
@@ -99,6 +102,11 @@ public void setupSuiteScopeCluster() throws Exception {
99102
client().admin().indices().prepareForceMerge(INDEX).setMaxNumSegments(1).get();
100103
}
101104

105+
@Before
106+
public void reset() {
107+
SCRIPT_SEMAPHORE.drainPermits();
108+
}
109+
102110
public void testFiltersCountCancellation() throws Exception {
103111
ensureProperCancellation(
104112
client().prepareSearch(INDEX)
@@ -129,14 +137,14 @@ public void testFiltersSubAggsCancellation() throws Exception {
129137

130138
private void ensureProperCancellation(SearchRequestBuilder searchRequestBuilder) throws Exception {
131139
var searchRequestFuture = searchRequestBuilder.setTimeout(TimeValue.timeValueSeconds(1)).execute();
132-
assertFalse(searchRequestFuture.isCancelled());
133-
assertFalse(searchRequestFuture.isDone());
140+
assertThat(searchRequestFuture.isCancelled(), equalTo(false));
141+
assertThat(searchRequestFuture.isDone(), equalTo(false));
134142

135143
// Check that there are search tasks running
136144
assertThat(getSearchTasks(), not(empty()));
137145

138146
// Wait for the script field to get blocked
139-
assertBusy(() -> { assertThat(SCRIPT_SEMAPHORE.getQueueLength(), greaterThan(0)); });
147+
assertBusy(() -> assertThat(SCRIPT_SEMAPHORE.getQueueLength(), greaterThan(0)));
140148

141149
// Cancel the tasks
142150
// Warning: Adding a waitForCompletion(true)/execute() here sometimes causes tasks to not get canceled and threads to get stuck
@@ -146,8 +154,8 @@ private void ensureProperCancellation(SearchRequestBuilder searchRequestBuilder)
146154

147155
// Ensure the search request finished and that there are no more search tasks
148156
assertBusy(() -> {
149-
assertTrue(searchRequestFuture.isDone());
150-
assertThat(getSearchTasks(), empty());
157+
assertThat("Search request didn't finish", searchRequestFuture.isDone(), equalTo(true));
158+
assertThat("There are dangling search tasks", getSearchTasks(), empty());
151159
});
152160
}
153161

0 commit comments

Comments
 (0)