Skip to content

Commit 0790fff

Browse files
vinodkccloud-fan
authored andcommitted
[SPARK-54551][CONNECT][TESTS][FOLLOWUP] Redirect Test Spark connect server output stream to files
### What changes were proposed in this pull request? Currently, the Spark Connect test server's stdout and stderr are discarded when SPARK_DEBUG_SC_JVM_CLIENT=false, making it difficult to debug test failures. This PR enables log4j logging for Test Spark Connect server in all test modes (both debug and non-debug) by always configuring log4j2.properties. ### Why are the changes needed? When `SPARK_DEBUG_SC_JVM_CLIENT=false` SparkConnectJdbcDataTypeSuite randomly hangs because the child server process blocks on write() calls when stdout/stderr pipe buffers fill up. Without consuming the output, the buffers reach capacity and cause the process to block indefinitely. Instead of `Redirect.DISCARD` , redirect the logs into log4j files ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Tested and confirmed that log files are created when 1) `SPARK_DEBUG_SC_JVM_CLIENT=false build/sbt "connect-client-jdbc/testOnly org.apache.spark.sql.connect.client.jdbc.SparkConnectJdbcDataTypeSuite"` OR 2) `SPARK_DEBUG_SC_JVM_CLIENT=true build/sbt "connect-client-jdbc/testOnly org.apache.spark.sql.connect.client.jdbc.SparkConnectJdbcDataTypeSuite"` ``` In this file ./target/unit-tests.log ``` ### Was this patch authored or co-authored using generative AI tooling? No. Closes #53275 from vinodkc/br_redirect_stdout_stderr_to_file. Authored-by: vinodkc <vinod.kc.in@gmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
1 parent 095c2c3 commit 0790fff

File tree

2 files changed

+17
-26
lines changed

2 files changed

+17
-26
lines changed

sql/connect/client/jvm/src/test/scala/org/apache/spark/sql/connect/test/IntegrationTestUtils.scala

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,21 @@ object IntegrationTestUtils {
5959
s"$connectClientHomeDir/target/$scalaDir/test-classes"
6060
}
6161

62-
private[sql] def debugConfigs: Seq[String] = {
62+
private[sql] def log4jConfigs: Seq[String] = {
6363
val log4j2 = s"$connectClientHomeDir/src/test/resources/log4j2.properties"
64-
if (isDebug) {
65-
Seq(
66-
// Enable to see the server plan change log
67-
// "--conf",
68-
// "spark.sql.planChangeLog.level=WARN",
69-
70-
// Enable to see the server grpc received
71-
// "--conf",
72-
// "spark.connect.grpc.interceptor.classes=" +
73-
// "org.apache.spark.sql.connect.service.LoggingInterceptor",
74-
75-
// Redirect server log into console
76-
"--conf",
77-
s"spark.driver.extraJavaOptions=-Dlog4j.configurationFile=$log4j2")
78-
} else Seq.empty
64+
Seq(
65+
// Enable to see the server plan change log
66+
// "--conf",
67+
// "spark.sql.planChangeLog.level=WARN",
68+
69+
// Enable to see the server grpc received
70+
// "--conf",
71+
// "spark.connect.grpc.interceptor.classes=" +
72+
// "org.apache.spark.sql.connect.service.LoggingInterceptor",
73+
74+
// Redirect server log into console
75+
"--conf",
76+
s"spark.driver.extraJavaOptions=-Dlog4j.configurationFile=$log4j2")
7977
}
8078

8179
// Log server start stop debug info into console

sql/connect/client/jvm/src/test/scala/org/apache/spark/sql/connect/test/RemoteSparkSession.scala

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ object SparkConnectServerUtils {
7777
command += "--jars" += catalystTestJar
7878
command += "--conf" += s"spark.connect.grpc.binding.port=$port"
7979
command ++= testConfigs
80-
command ++= debugConfigs
80+
command ++= log4jConfigs
8181
command += connectJar
8282
val cmds = command.result()
8383
debug {
@@ -90,15 +90,8 @@ object SparkConnectServerUtils {
9090
builder.directory(new File(sparkHome))
9191
val environment = builder.environment()
9292
environment.remove("SPARK_DIST_CLASSPATH")
93-
if (isDebug) {
94-
builder.redirectError(Redirect.INHERIT)
95-
builder.redirectOutput(Redirect.INHERIT)
96-
} else {
97-
// If output is not consumed, the stdout/stderr pipe buffers will fill up,
98-
// causing the server process to block on write() calls
99-
builder.redirectError(Redirect.DISCARD)
100-
builder.redirectOutput(Redirect.DISCARD)
101-
}
93+
builder.redirectError(Redirect.INHERIT)
94+
builder.redirectOutput(Redirect.INHERIT)
10295

10396
val process = builder.start()
10497
consoleOut = process.getOutputStream

0 commit comments

Comments
 (0)