Skip to content

Commit b245348

Browse files
authored
Busily assert in testCreateSearchContextFailure (#64243)
If a background refresh is running, then the refCount assertion will fail as Engine#refreshIsNeeded can increase the refCount by 2. Closes #64052
1 parent d6c6563 commit b245348

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

server/src/test/java/org/elasticsearch/search/SearchServiceTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ public void testCreateSearchContext() throws IOException {
891891
* While we have no NPE in DefaultContext constructor anymore, we still want to guard against it (or other failures) in the future to
892892
* avoid leaking searchers.
893893
*/
894-
public void testCreateSearchContextFailure() throws IOException {
894+
public void testCreateSearchContextFailure() throws Exception {
895895
final String index = randomAlphaOfLengthBetween(5, 10).toLowerCase(Locale.ROOT);
896896
final IndexService indexService = createIndex(index);
897897
final SearchService service = getInstanceFromNode(SearchService.class);
@@ -908,7 +908,9 @@ public SearchType searchType() {
908908
() -> service.createContext(reader, request, null, randomBoolean()));
909909
assertEquals("expected", e.getMessage());
910910
}
911-
assertEquals("should have 2 store refs (IndexService + InternalEngine)", 2, indexService.getShard(0).store().refCount());
911+
// Needs to busily assert because Engine#refreshNeeded can increase the refCount.
912+
assertBusy(() ->
913+
assertEquals("should have 2 store refs (IndexService + InternalEngine)", 2, indexService.getShard(0).store().refCount()));
912914
}
913915

914916
public void testMatchNoDocsEmptyResponse() throws InterruptedException {

0 commit comments

Comments
 (0)