Skip to content

Commit 84f7279

Browse files
Fix search response leaks in EQL tests (#103068)
Fixing all EQL tests
1 parent be1277a commit 84f7279

File tree

4 files changed

+51
-50
lines changed

4 files changed

+51
-50
lines changed

x-pack/plugin/eql/src/test/java/org/elasticsearch/xpack/eql/execution/assembler/ImplicitTiebreakerTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ public void query(QueryRequest r, ActionListener<SearchResponse> l) {
8484
);
8585
SearchHits searchHits = new SearchHits(new SearchHit[] { searchHit }, new TotalHits(1, Relation.EQUAL_TO), 0.0f);
8686
SearchResponseSections internal = new SearchResponseSections(searchHits, null, null, false, false, null, 0);
87-
SearchResponse s = new SearchResponse(internal, null, 0, 1, 0, 0, null, Clusters.EMPTY);
88-
l.onResponse(s);
87+
ActionListener.respondAndRelease(l, new SearchResponse(internal, null, 0, 1, 0, 0, null, Clusters.EMPTY));
8988
}
9089

9190
@Override

x-pack/plugin/eql/src/test/java/org/elasticsearch/xpack/eql/execution/assembler/SequenceSpecTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,7 @@ public void query(QueryRequest r, ActionListener<SearchResponse> l) {
222222
0.0f
223223
);
224224
SearchResponseSections internal = new SearchResponseSections(searchHits, null, null, false, false, null, 0);
225-
SearchResponse s = new SearchResponse(internal, null, 0, 1, 0, 0, null, Clusters.EMPTY);
226-
l.onResponse(s);
225+
ActionListener.respondAndRelease(l, new SearchResponse(internal, null, 0, 1, 0, 0, null, Clusters.EMPTY));
227226
}
228227

229228
@Override

x-pack/plugin/eql/src/test/java/org/elasticsearch/xpack/eql/execution/sample/CircuitBreakerTests.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,19 +224,20 @@ <Response extends ActionResponse> void handleSearchRequest(ActionListener<Respon
224224
Aggregations aggs = new Aggregations(List.of(newInternalComposite()));
225225

226226
SearchResponseSections internal = new SearchResponseSections(null, aggs, null, false, false, null, 0);
227-
SearchResponse response = new SearchResponse(
228-
internal,
229-
null,
230-
2,
231-
0,
232-
0,
233-
0,
234-
ShardSearchFailure.EMPTY_ARRAY,
235-
Clusters.EMPTY,
236-
searchRequest.pointInTimeBuilder().getEncodedId()
227+
ActionListener.respondAndRelease(
228+
listener,
229+
(Response) new SearchResponse(
230+
internal,
231+
null,
232+
2,
233+
0,
234+
0,
235+
0,
236+
ShardSearchFailure.EMPTY_ARRAY,
237+
Clusters.EMPTY,
238+
searchRequest.pointInTimeBuilder().getEncodedId()
239+
)
237240
);
238-
239-
listener.onResponse((Response) response);
240241
}
241242

242243
private InternalComposite newInternalComposite() {

x-pack/plugin/eql/src/test/java/org/elasticsearch/xpack/eql/execution/sequence/CircuitBreakerTests.java

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ public void query(QueryRequest r, ActionListener<SearchResponse> l) {
115115
);
116116
SearchHits searchHits = new SearchHits(new SearchHit[] { searchHit }, new TotalHits(1, Relation.EQUAL_TO), 0.0f);
117117
SearchResponseSections internal = new SearchResponseSections(searchHits, null, null, false, false, null, 0);
118-
SearchResponse s = new SearchResponse(internal, null, 0, 1, 0, 0, null, Clusters.EMPTY);
119-
l.onResponse(s);
118+
ActionListener.respondAndRelease(l, new SearchResponse(internal, null, 0, 1, 0, 0, null, Clusters.EMPTY));
120119
}
121120

122121
@Override
@@ -451,7 +450,7 @@ <Response extends ActionResponse> void handleSearchRequest(ActionListener<Respon
451450
assertTrue(circuitBreaker.getUsed() > 0); // at this point the algorithm already started adding up to memory usage
452451
}
453452

454-
listener.onResponse((Response) response);
453+
ActionListener.respondAndRelease(listener, (Response) response);
455454
}
456455
}
457456

@@ -479,18 +478,20 @@ <Response extends ActionResponse> void handleSearchRequest(ActionListener<Respon
479478
);
480479
SearchHits searchHits = new SearchHits(new SearchHit[] { searchHit }, new TotalHits(1, Relation.EQUAL_TO), 0.0f);
481480
SearchResponseSections internal = new SearchResponseSections(searchHits, null, null, false, false, null, 0);
482-
SearchResponse response = new SearchResponse(
483-
internal,
484-
null,
485-
2,
486-
0,
487-
0,
488-
0,
489-
ShardSearchFailure.EMPTY_ARRAY,
490-
SearchResponse.Clusters.EMPTY,
491-
searchRequest.pointInTimeBuilder().getEncodedId()
481+
ActionListener.respondAndRelease(
482+
listener,
483+
(Response) new SearchResponse(
484+
internal,
485+
null,
486+
2,
487+
0,
488+
0,
489+
0,
490+
ShardSearchFailure.EMPTY_ARRAY,
491+
SearchResponse.Clusters.EMPTY,
492+
searchRequest.pointInTimeBuilder().getEncodedId()
493+
)
492494
);
493-
listener.onResponse((Response) response);
494495
} else {
495496
assertTrue(circuitBreaker.getUsed() > 0); // at this point the algorithm already started adding up to memory usage
496497
ShardSearchFailure[] failures = new ShardSearchFailure[] {
@@ -504,28 +505,29 @@ <Response extends ActionResponse> void handleSearchRequest(ActionListener<Respon
504505
listener.onFailure(new SearchPhaseExecutionException("search", "all shards failed", failures));
505506
} else {
506507
// or a partial shard failure
507-
SearchResponse response = new SearchResponse(
508-
new InternalSearchResponse(
509-
new SearchHits(new SearchHit[] { new SearchHit(1) }, new TotalHits(1L, TotalHits.Relation.EQUAL_TO), 1.0f),
508+
// this should still be caught and the exception handled properly and circuit breaker cleared
509+
ActionListener.respondAndRelease(
510+
listener,
511+
(Response) new SearchResponse(
512+
new InternalSearchResponse(
513+
new SearchHits(new SearchHit[] { new SearchHit(1) }, new TotalHits(1L, TotalHits.Relation.EQUAL_TO), 1.0f),
514+
null,
515+
new Suggest(Collections.emptyList()),
516+
new SearchProfileResults(Collections.emptyMap()),
517+
false,
518+
false,
519+
1
520+
),
510521
null,
511-
new Suggest(Collections.emptyList()),
512-
new SearchProfileResults(Collections.emptyMap()),
513-
false,
514-
false,
515-
1
516-
),
517-
null,
518-
2,
519-
1,
520-
0,
521-
0,
522-
failures,
523-
SearchResponse.Clusters.EMPTY,
524-
searchRequest.pointInTimeBuilder().getEncodedId()
522+
2,
523+
1,
524+
0,
525+
0,
526+
failures,
527+
SearchResponse.Clusters.EMPTY,
528+
searchRequest.pointInTimeBuilder().getEncodedId()
529+
)
525530
);
526-
527-
// this should still be caught and the exception handled properly and circuit breaker cleared
528-
listener.onResponse((Response) response);
529531
}
530532
}
531533
}

0 commit comments

Comments
 (0)