Skip to content

Commit

Permalink
Bound random negative size test in SearchSourceBuilderTests#testNegat…
Browse files Browse the repository at this point in the history
…iveSizeErrors (#88457)

-1 is handled differently by the xcontent code path so this test will fail when `randomIntBetween` lands on -1.

To fix, we add another integer for the xcontent test which starts at -2.
  • Loading branch information
matschaffer authored Jul 12, 2022
1 parent c56715f commit 5628b87
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,12 @@ public void testNegativeSizeErrors() throws IOException {
expected = expectThrows(IllegalArgumentException.class, () -> new SearchSourceBuilder().size(-1));
assertEquals("[size] parameter cannot be negative, found [-1]", expected.getMessage());

String restContent = "{\"size\" : " + randomSize + "}";
// SearchSourceBuilder.fromXContent treats -1 as not-set
int boundedRandomSize = randomIntBetween(-100000, -2);
String restContent = "{\"size\" : " + boundedRandomSize + "}";
try (XContentParser parser = createParser(JsonXContent.jsonXContent, restContent)) {
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> SearchSourceBuilder.fromXContent(parser));
assertThat(ex.getMessage(), containsString(Integer.toString(randomSize)));
assertThat(ex.getMessage(), containsString(Integer.toString(boundedRandomSize)));
}

restContent = "{\"size\" : -1}";
Expand Down

0 comments on commit 5628b87

Please sign in to comment.