This is an automated email from the ASF dual-hosted git repository.
dongjoon-hyun pushed a commit to branch branch-4.x
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-4.x by this push:
new d24bff351284 [SPARK-56886][CORE][TESTS] Improve `UtilsSuite` to be
more robust
d24bff351284 is described below
commit d24bff351284eac3830131aa68ae6cb967007930
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Sat May 16 09:40:22 2026 +0200
[SPARK-56886][CORE][TESTS] Improve `UtilsSuite` to be more robust
### What changes were proposed in this pull request?
In `test("SPARK-35907: createDirectory")`, guard scenarios 4 and 5's
negative assertions with `if (!testDir.canWrite)` / `if (!testDir.canExecute)`,
so they only run when revoking the permission bit actually blocks access. The
`setWritable(true)` / `setExecutable(true)` restore calls stay outside the
guard.
### Why are the changes needed?
When the test runs as `root`, `File.setWritable(false)` /
`setExecutable(false)` do not actually block access (root bypasses POSIX
permission bits), so the negative assertions fail. Detecting the effective
permission via `canWrite` / `canExecute` is more accurate than username
heuristics and keeps full coverage for non-`root` runs.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Pass the CIs.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.7)
Closes #55911 from dongjoon-hyun/SPARK-56886.
Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Peter Toth <[email protected]>
(cherry picked from commit a9c953245954c17877354c6d733021d44760dde2)
Signed-off-by: Dongjoon Hyun <[email protected]>
---
.../test/scala/org/apache/spark/util/UtilsSuite.scala | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/core/src/test/scala/org/apache/spark/util/UtilsSuite.scala
b/core/src/test/scala/org/apache/spark/util/UtilsSuite.scala
index e87f3ad02649..4bb46959cef8 100644
--- a/core/src/test/scala/org/apache/spark/util/UtilsSuite.scala
+++ b/core/src/test/scala/org/apache/spark/util/UtilsSuite.scala
@@ -527,18 +527,24 @@ class UtilsSuite extends SparkFunSuite with
ResetSystemProperties {
val scenario4 = new File(testDir, "scenario4")
assert(testDir.canWrite)
assert(testDir.setWritable(false))
- assert(!Utils.createDirectory(scenario4))
- assert(!scenario4.exists())
- assertThrows[IOException](Utils.createDirectory(testDirPath, "scenario4"))
+ // Skip when write permission cannot actually be revoked (e.g., running as
root).
+ if (!testDir.canWrite) {
+ assert(!Utils.createDirectory(scenario4))
+ assert(!scenario4.exists())
+ assertThrows[IOException](Utils.createDirectory(testDirPath,
"scenario4"))
+ }
assert(testDir.setWritable(true))
// 5. The parent directory cannot execute
val scenario5 = new File(testDir, "scenario5")
assert(testDir.canExecute)
assert(testDir.setExecutable(false))
- assert(!Utils.createDirectory(scenario5))
- assert(!scenario5.exists())
- assertThrows[IOException](Utils.createDirectory(testDirPath, "scenario5"))
+ // Skip when execute permission cannot actually be revoked (e.g., running
as root).
+ if (!testDir.canExecute) {
+ assert(!Utils.createDirectory(scenario5))
+ assert(!scenario5.exists())
+ assertThrows[IOException](Utils.createDirectory(testDirPath,
"scenario5"))
+ }
assert(testDir.setExecutable(true))
// The following 3 scenarios are only for the method: createDirectory(File)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]