Skip to content

Commit

Permalink
Add additional logging around testShouldSearchAll tests (#3932)
Browse files Browse the repository at this point in the history
### Description
- Improve error message logging on mismatch in search response.  

#### Example of new error message:
```
Suite: Test class org.opensearch.security.DlsIntegrationTests
  2> java.lang.AssertionError: 
    Expected: Search hit with index <5> should contain field "artist"" with value equal to ""yes"
         but: Unexpected match in SearchResponse {"took":101,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":6,"relation":"eq"},"max_score":null,"hits":[{"_index":"first-test-index","_id":"INDEX_1_S1","_score":null,"_source":{"artist":"First artist","lyrics":"Very deep subject","stars":1,"genre":"rock","title":"Magnum Opus"},"sort":["INDEX_1_S1"]},{"_index":"first-test-index","_id":"INDEX_1_S2","_score":null,"_source":{"artist":"String","lyrics":"Once upon a time","stars":2,"genre":"blues","title":"Song 1+1"},"sort":["INDEX_1_S2"]},{"_index":"first-test-index","_id":"INDEX_1_S3","_score":null,"_source":{"artist":"Twins","lyrics":"giant nonsense","stars":3,"genre":"jazz","title":"Next song"},"sort":["INDEX_1_S3"]},{"_index":"first-test-index","_id":"INDEX_1_S4","_score":null,"_source":{"artist":"No!","lyrics":"Much too much","stars":4,"genre":"rock","title":"Poison"},"sort":["INDEX_1_S4"]},{"_index":"first-test-index","_id":"INDEX_1_S5","_score":null,"_source":{"artist":"yes","lyrics":"Little to little","stars":5,"genre":"blues","title":"Affirmative"},"sort":["INDEX_1_S5"]},{"_index":"first-test-index","_id":"INDEX_1_S6","_score":null,"_source":{"artist":"unknown","lyrics":"confidential secret classified","stars":6,"genre":"jazz","title":"confidential"},"sort":["INDEX_1_S6"]}]}}
    Field value is equal to "unknown"
        at __randomizedtesting.SeedInfo.seed([2CB66291B43A24:7C34555162F056C]:0)
        at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
        at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:6)
        at org.opensearch.security.DlsIntegrationTests.testShouldSearchAll(DlsIntegrationTests.java:294)
```

### Issues Resolved
- Resolved #3830

### Testing
Ran the suite of integration tests with
[10x](https://github.com/opensearch-project/security/actions/runs/7464876335?pr=3932)
with no failures.

### Check List
- [ ] ~New functionality includes testing~
- [ ] ~New functionality has been documented~
- [x] Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and
signing off your commits, please check
[here](https://github.com/opensearch-project/OpenSearch/blob/main/CONTRIBUTING.md#developer-certificate-of-origin).

---------

Signed-off-by: Peter Nied <petern@amazon.com>
  • Loading branch information
peternied authored Jan 11, 2024
1 parent b8a315a commit fdfe087
Showing 1 changed file with 1 addition and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SearchHitContainsFieldWithValueMatcher<T> extends TypeSafeDiagnosingMatche

@Override
protected boolean matchesSafely(SearchResponse searchResponse, Description mismatchDescription) {
mismatchDescription.appendText("Unexpected match in SearchResponse " + searchResponse.toString() + "\n");
Long numberOfHits = readTotalHits(searchResponse);
if (numberOfHits == null) {
mismatchDescription.appendText("Total number of hits is unknown.");
Expand Down

0 comments on commit fdfe087

Please sign in to comment.