Skip to content

Commit 21d2a64

Browse files
committed
Update unit tests to handle platforms with larger default stack sizes (#69164)
1 parent b3a6ae1 commit 21d2a64

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

x-pack/plugin/sql/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,10 @@ if (BuildParams.inFipsJvm){
139139
// Test clusters run with security disabled
140140
tasks.named("internalClusterTest").configure{enabled = false }
141141
}
142+
143+
tasks.named("test").configure {
144+
// SqlParserTests need some extra cushion on Java 8 due to tests that explicitly try to generate StackOverflowExceptions
145+
if (BuildParams.runtimeJavaVersion == JavaVersion.VERSION_1_8) {
146+
maxHeapSize = "1g"
147+
}
148+
}

x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/parser/SqlParserTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ public void testLimitToPreventStackOverflowFromLargeBinaryBooleanExpression() {
255255
// 1000 elements is ok
256256
new SqlParser().createExpression(join(" OR ", nCopies(1000, "a = b")));
257257

258-
// 5000 elements cause stack overflow
258+
// 10000 elements cause stack overflow
259259
ParsingException e = expectThrows(ParsingException.class, () ->
260-
new SqlParser().createExpression(join(" OR ", nCopies(5000, "a = b"))));
260+
new SqlParser().createExpression(join(" OR ", nCopies(10000, "a = b"))));
261261
assertThat(e.getMessage(),
262262
startsWith("line -1:0: SQL statement is too large, causing stack overflow when generating the parsing tree: ["));
263263
}
@@ -271,7 +271,7 @@ public void testLimitToPreventStackOverflowFromLargeUnaryArithmeticExpression()
271271

272272
// 5000 elements cause stack overflow
273273
ParsingException e = expectThrows(ParsingException.class, () -> new SqlParser().createExpression(
274-
join("", nCopies(1000, "abs(")).concat("i").concat(join("", nCopies(1000, ")")))));
274+
join("", nCopies(5000, "abs(")).concat("i").concat(join("", nCopies(5000, ")")))));
275275
assertThat(e.getMessage(),
276276
startsWith("line -1:0: SQL statement is too large, causing stack overflow when generating the parsing tree: ["));
277277
}
@@ -282,9 +282,9 @@ public void testLimitToPreventStackOverflowFromLargeBinaryArithmeticExpression()
282282
// 1000 elements is ok
283283
new SqlParser().createExpression(join(" + ", nCopies(1000, "a")));
284284

285-
// 5000 elements cause stack overflow
285+
// 10000 elements cause stack overflow
286286
ParsingException e = expectThrows(ParsingException.class, () ->
287-
new SqlParser().createExpression(join(" + ", nCopies(5000, "a"))));
287+
new SqlParser().createExpression(join(" + ", nCopies(10000, "a"))));
288288
assertThat(e.getMessage(),
289289
startsWith("line -1:0: SQL statement is too large, causing stack overflow when generating the parsing tree: ["));
290290
}
@@ -298,11 +298,11 @@ public void testLimitToPreventStackOverflowFromLargeSubselectTree() {
298298
.concat("t")
299299
.concat(join("", nCopies(199, ")"))));
300300

301-
// 500 elements cause stack overflow
301+
// 1000 elements cause stack overflow
302302
ParsingException e = expectThrows(ParsingException.class, () -> new SqlParser().createStatement(
303-
join(" (", nCopies(500, "SELECT * FROM"))
303+
join(" (", nCopies(1000, "SELECT * FROM"))
304304
.concat("t")
305-
.concat(join("", nCopies(499, ")")))));
305+
.concat(join("", nCopies(999, ")")))));
306306
assertThat(e.getMessage(),
307307
startsWith("line -1:0: SQL statement is too large, causing stack overflow when generating the parsing tree: ["));
308308
}

0 commit comments

Comments
 (0)