Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update elasticsearch.modules.parent-join.internalClusterTest #102189

Conversation

JVerwolf
Copy link
Contributor

Part of the broader work covered in #102030

Updates tests in:

  • ChildQuerySearchIT
  • TokenCountFieldMapperIntegrationIT

@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label v8.12.0 labels Nov 14, 2023
@JVerwolf JVerwolf added >test Issues or PRs that are addressing/adding tests :Search/Search Search-related issues that do not fall into other categories labels Nov 14, 2023
@elasticsearchmachine elasticsearchmachine added Team:Search Meta label for search team and removed needs:triage Requires assignment of a team area label labels Nov 14, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

@JVerwolf
Copy link
Contributor Author

@elasticmachine update branch

@@ -364,6 +369,26 @@ public static void assertResponse(ActionRequestBuilder<?, SearchResponse> search
}
}

public static void assertScrollResponses(SearchRequestBuilder searchRequestBuilder, Consumer<List<SearchResponse>> consumer) {
var timoutSeconds = 30;
Copy link
Contributor

@iverase iverase Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting approach. Could you check if you can use this method with the test in #102053?

Maybe the timeout should be an input to the method?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW: This method should be able to handle the cases in TransportTwoNodesSearchIT which I am trying to work out. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @iverase, I'll take a look. Sure, I can make the timeout an input.

I tried a few different approaches, but settled on making the consumer accept the list of partial responses. That way, the caller can decide if they want to validate individual aspects of the the response and/or the whole thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out 0ab8fd6

This updates the test you linked.

I changed assertScrollResponses to return a record of "slices" on the result list. This now makes it easy for the tests to iterate over the the various aspects of the Scroll and perform thier assertions without duplicating the slicing logic each time.

responses.add(scrollResponse);
try {
while (scrollResponse.getHits().getHits().length > 0) {
scrollResponse = client().prepareSearchScroll(scrollResponse.getScrollId())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add to ESIngestTestCase a method so we don't have to create the query here. Something like:

 public static SearchScrollRequestBuilder prepareScrollSearch(String scrollId, TimeValue timeout) {
        return client().prepareSearchScroll(scrollId).setScroll(timeout);
   }

) {}

public static void assertScrollResponses(
int timoutSeconds,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use a TimeValue here.

responses
)
);
clearScroll(scrollResponse.getScrollId());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go in the finally block?

);
clearScroll(scrollResponse.getScrollId());
} finally {
responses.forEach(TransportMessage::decRef);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

responses.forEach(SearchResponse::decRef);

So we dont need an extra import

Copy link
Contributor

@iverase iverase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a fundamental concern with your approach as some test might want to perform actions between scroll calls instead of asserting after all queries have been done. I wonder if something more specialize would be better here, something on these lines:

  public static void assertTotalHitsAndResponses(
        TimeValue keepAlive,
        SearchRequestBuilder searchRequestBuilder,
        Consumer<SearchResponse> initialSearchResponse,
        Consumer<SearchResponse> scrollResponses,
        int totalHits
    ) {
        searchRequestBuilder.setScroll(keepAlive);
        List<SearchResponse> responses = new ArrayList<>();
        var scrollResponse = searchRequestBuilder.get();
        responses.add(scrollResponse);
        int countDocs = 0;
        try {
            assertThat(scrollResponse.getHits().getTotalHits().value, equalTo((long) totalHits));
            countDocs += scrollResponse.getHits().getHits().length;
            initialSearchResponse.accept(scrollResponse);
            while (scrollResponse.getHits().getHits().length > 0) {
                scrollResponse = prepareScrollSearch(scrollResponse.getScrollId(), keepAlive).get();
                responses.add(scrollResponse);
                assertThat(scrollResponse.getHits().getTotalHits().value, equalTo((long) totalHits));
                countDocs += scrollResponse.getHits().getHits().length;
                scrollResponses.accept(scrollResponse);
            }
        } finally {
            clearScroll(scrollResponse.getScrollId());
            responses.forEach(SearchResponse::decRef);
        }
        assertThat(countDocs, equalTo(totalHits));
    }

Copy link
Member

@original-brownbear original-brownbear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 questions, sorry it took me so long to get to this one!

@@ -1306,40 +1307,23 @@ public void testParentChildQueriesNoParentType() throws Exception {
client().prepareIndex("test").setId(parentId).setSource("p_field", "1").get();
refresh();

try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to fix these? For the exception case the production code should handle any ref counting?
Maybe a cleanup best left for another PR since it's unrelated to this effort?

} while (scrollResponse.getHits().getHits().length > 0);
clearScroll(scrollResponse.getScrollId());
assertThat(scannedDocs, equalTo(10));
assertScrollResponses(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the timeout here? Can we maybe just remove the timeout from this test to not have to bother with timeouts? (those are a known tricky issue around ref counting actually ...)

Copy link
Contributor Author

@JVerwolf JVerwolf Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The search request builder requires it (unless I'm mistaken), though mabye I can create the search directly so that I don't have to refactor the builder. I could probably change this with a broader refactor, but isn't timeouts something we have to handle anyways?

@JVerwolf
Copy link
Contributor Author

JVerwolf commented Dec 2, 2023

@iverase

I have a fundamental concern with your approach as some test might want to perform actions between scroll calls instead of asserting after all queries have been done. I wonder if something more specialize would be better here, something on these lines:

  public static void assertTotalHitsAndResponses(
        TimeValue keepAlive,
        SearchRequestBuilder searchRequestBuilder,
        Consumer<SearchResponse> initialSearchResponse,
        Consumer<SearchResponse> scrollResponses,
        int totalHits
    ) {
        searchRequestBuilder.setScroll(keepAlive);
        List<SearchResponse> responses = new ArrayList<>();
        var scrollResponse = searchRequestBuilder.get();
        responses.add(scrollResponse);
        int countDocs = 0;
        try {
            assertThat(scrollResponse.getHits().getTotalHits().value, equalTo((long) totalHits));
            countDocs += scrollResponse.getHits().getHits().length;
            initialSearchResponse.accept(scrollResponse);
            while (scrollResponse.getHits().getHits().length > 0) {
                scrollResponse = prepareScrollSearch(scrollResponse.getScrollId(), keepAlive).get();
                responses.add(scrollResponse);
                assertThat(scrollResponse.getHits().getTotalHits().value, equalTo((long) totalHits));
                countDocs += scrollResponse.getHits().getHits().length;
                scrollResponses.accept(scrollResponse);
            }
        } finally {
            clearScroll(scrollResponse.getScrollId());
            responses.forEach(SearchResponse::decRef);
        }
        assertThat(countDocs, equalTo(totalHits));
    }

Let's go a step further and allow the user to decide which request they want to interact with, and in doing so, simplify the api. I've updated the code to this effect. WDYT?

Copy link
Contributor

@iverase iverase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@original-brownbear original-brownbear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, hope you don't mind me just merging this John! Looks good and removes some noise from my work on this :) Thanks!

@original-brownbear original-brownbear merged commit 80b222c into elastic:main Dec 9, 2023
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team >test Issues or PRs that are addressing/adding tests v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants