This is an automated email from the ASF dual-hosted git repository.

taiyang-li pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gluten.git


The following commit(s) were added to refs/heads/main by this push:
     new 311dec6a45 [TEST] Support configurable test working directories 
(#13110)
311dec6a45 is described below

commit 311dec6a4532e3c7c1059c9f2948e9497d364e70
Author: Zhang Xiaofeng <[email protected]>
AuthorDate: Thu Sep 24 10:22:22 2026 +0800

    [TEST] Support configurable test working directories (#13110)
    
    * test: allow configuring Gluten test directories
    
    Let test launchers assign a private base directory to each JVM through
    gluten.test.dir, avoiding shared warehouse and metastore paths when
    running suites concurrently. Preserve the existing default directory.
    
    Document that suites remove the configured directory during cleanup and
    test both the default and overridden paths without creating a Spark session.
    
    * test: keep Gluten working files under the configured test directory
    
    Treat gluten.test.dir as the parent of unit-tests-working-home so suite
    initialization only resets its own working directory and preserves other
    files in the configured parent. Keep the default location unchanged.
    
    Cover directory initialization and preservation of sibling files, and
    remove the trait comment describing the previous cleanup behavior.
    
    * test: simplify Gluten test directory coverage
    
    Rename the suite around the test-directory behavior and use SparkFunSuite's
    temporary-directory helper. Combine custom path and cleanup assertions in
    one filesystem test while retaining default-path coverage and restoring
    the system property after each check.
    
    The two tests, Spotless check and license header check pass.
---
 .../spark/sql/GlutenTestDirectorySuite.scala       | 65 ++++++++++++++++++++++
 .../apache/spark/sql/GlutenTestsBaseTrait.scala    |  5 +-
 2 files changed, 69 insertions(+), 1 deletion(-)

diff --git 
a/gluten-ut/common/src/test/scala/org/apache/spark/sql/GlutenTestDirectorySuite.scala
 
b/gluten-ut/common/src/test/scala/org/apache/spark/sql/GlutenTestDirectorySuite.scala
new file mode 100644
index 0000000000..647a4b9941
--- /dev/null
+++ 
b/gluten-ut/common/src/test/scala/org/apache/spark/sql/GlutenTestDirectorySuite.scala
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.spark.sql
+
+import org.apache.spark.SparkFunSuite
+
+import org.apache.commons.io.FileUtils
+
+import java.io.File
+
+class GlutenTestDirectorySuite extends SparkFunSuite {
+
+  private class TestPaths extends GlutenSQLTestsTrait {
+    def directory: String = basePath
+    def defaultDirectory: String = rootPath + "unit-tests-working-home"
+  }
+
+  private def withTestDirectory(directory: Option[String])(f: TestPaths => 
Unit): Unit = {
+    val previous = sys.props.remove("gluten.test.dir")
+    try {
+      directory.foreach(value => sys.props.put("gluten.test.dir", value))
+      f(new TestPaths)
+    } finally {
+      sys.props.remove("gluten.test.dir")
+      previous.foreach(value => sys.props.put("gluten.test.dir", value))
+    }
+  }
+
+  test("default test directory") {
+    withTestDirectory(None)(paths => assert(paths.directory == 
paths.defaultDirectory))
+  }
+
+  test("custom test directory cleanup") {
+    withTempDir {
+      parent =>
+        val retained = new File(parent, "keep")
+        val working = new File(parent, "unit-tests-working-home")
+        val stale = new File(working, "stale")
+        FileUtils.touch(retained)
+        FileUtils.touch(stale)
+        withTestDirectory(Some(parent.getAbsolutePath)) {
+          paths =>
+            paths.prepareWorkDir()
+            assert(retained.isFile)
+            assert(!stale.exists())
+            assert(new File(working, "spark-warehouse").isDirectory)
+            assert(new File(working, "meta").isDirectory)
+        }
+    }
+  }
+}
diff --git 
a/gluten-ut/common/src/test/scala/org/apache/spark/sql/GlutenTestsBaseTrait.scala
 
b/gluten-ut/common/src/test/scala/org/apache/spark/sql/GlutenTestsBaseTrait.scala
index a0ab973061..c516022080 100644
--- 
a/gluten-ut/common/src/test/scala/org/apache/spark/sql/GlutenTestsBaseTrait.scala
+++ 
b/gluten-ut/common/src/test/scala/org/apache/spark/sql/GlutenTestsBaseTrait.scala
@@ -24,10 +24,13 @@ import org.scalactic.source.Position
 import org.scalatest.Tag
 import org.scalatest.funsuite.AnyFunSuiteLike
 
+import java.io.File
+
 trait GlutenTestsBaseTrait extends AnyFunSuiteLike {
 
   protected val rootPath: String = getClass.getResource("/").getPath
-  protected val basePath: String = rootPath + "unit-tests-working-home"
+  protected val basePath: String =
+    new File(sys.props.getOrElse("gluten.test.dir", rootPath), 
"unit-tests-working-home").getPath
 
   protected val warehouse: String = basePath + "/spark-warehouse"
   protected val metaStorePathAbsolute: String = basePath + "/meta"


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to