Skip to content

Commit 5628b87

Browse files
authored
Bound random negative size test in SearchSourceBuilderTests#testNegativeSizeErrors (#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.
1 parent c56715f commit 5628b87

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

server/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,12 @@ public void testNegativeSizeErrors() throws IOException {
500500
expected = expectThrows(IllegalArgumentException.class, () -> new SearchSourceBuilder().size(-1));
501501
assertEquals("[size] parameter cannot be negative, found [-1]", expected.getMessage());
502502

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

509511
restContent = "{\"size\" : -1}";

0 commit comments

Comments
 (0)