From db4f92f0cb52e7ae57c5d7fceb20f347aff389a3 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Sun, 8 Oct 2023 20:42:12 -0700 Subject: [PATCH] Release discarded pages in mutateInstance (#100472) EsqlQueryResponseTests.testEqualsAndHashcode failed on CI because we did not release pages were discarded by randomValueOtherThan while mutating the testing instance. --- .../xpack/esql/action/EsqlQueryResponseTests.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/action/EsqlQueryResponseTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/action/EsqlQueryResponseTests.java index 7920e0575fd89..d71d0074c7ec0 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/action/EsqlQueryResponseTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/action/EsqlQueryResponseTests.java @@ -28,6 +28,7 @@ import org.elasticsearch.compute.data.LongBlock; import org.elasticsearch.compute.data.Page; import org.elasticsearch.compute.lucene.UnsupportedValueSource; +import org.elasticsearch.core.Releasables; import org.elasticsearch.test.AbstractChunkedSerializingTestCase; import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentType; @@ -136,11 +137,12 @@ protected EsqlQueryResponse mutateInstance(EsqlQueryResponse instance) { case 1 -> new EsqlQueryResponse(instance.columns(), deepCopyOfPages(instance), false == instance.columnar()); case 2 -> { int noPages = instance.pages().size(); - yield new EsqlQueryResponse( - instance.columns(), - randomValueOtherThan(instance.pages(), () -> randomList(noPages, noPages, () -> randomPage(instance.columns()))), - instance.columnar() - ); + List differentPages = List.of(); + do { + differentPages.forEach(p -> Releasables.closeExpectNoException(p::releaseBlocks)); + differentPages = randomList(noPages, noPages, () -> randomPage(instance.columns())); + } while (differentPages.equals(instance.pages())); + yield new EsqlQueryResponse(instance.columns(), differentPages, instance.columnar()); } default -> throw new IllegalArgumentException(); };