eclipse-ee4j / glassfish

Eclipse GlassFish
https://eclipse-ee4j.github.io/glassfish/
377 stars 143 forks source link

FileUtilsTest fails on clean build #25089

Closed Thihup closed 1 day ago

Thihup commented 1 month ago

Trying to build Glassfish with JDK 21 yield the following error:

[INFO] Results:
[INFO] 
[ERROR] Failures: 
[ERROR]   FileUtilsTest.testCopyDirectoriesFiles:91 expected: <29> but was: <60>
[INFO] 
[ERROR] Tests run: 2116, Failures: 1, Errors: 0, Skipped: 2
    @Test
    public void testCopyDirectoriesFiles() throws Exception {
        File outputDir = new File(tempDir, "outputDir");
        File testDir = new File(FileUtilsTest.class.getResource("/process").toURI());
        FileUtils.copy(testDir, outputDir);
        assertEquals(testDir.length(), outputDir.length());
    }

The value of both variables:

testDir: /workspace/glassfish/nucleus/common/common-util/target/test-classes/process outputDir: /tmp/junit4564666456115382502/outputDir

The [Files::length](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/File.html#length()) states: The return value is unspecified if this pathname denotes a directory.

Is this test actually testing what it should? Is this test failure expected?

dmatej commented 1 month ago

Just for curiosity - which operating system do you use? On CI it returns the same, on all my Ubuntu based systems too. It is a good catch and you are right, I just want to learn which system does it differently. Also we have to find a different way to verify that FileUtils.copy works for directories.

Thihup commented 1 month ago

Currently I'm using

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.4 LTS"
Apache Maven 3.9.8 (36645f6c9b5079805ea5009217e36f2cffd34256)
Maven home: /home/gitpod/.sdkman/candidates/maven/current
Java version: 21.0.4, vendor: Oracle Corporation, runtime: /home/gitpod/.sdkman/candidates/java/21.0.4-graal
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "6.1.91-060191-generic", arch: "amd64", family: "unix"
java 21.0.4 2024-07-16 LTS
Java(TM) SE Runtime Environment Oracle GraalVM 21.0.4+8.1 (build 21.0.4+8-LTS-jvmci-23.1-b41)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.4+8.1 (build 21.0.4+8-LTS-jvmci-23.1-b41, mixed mode, sharing)

From Gitpod.

It also fails with the default JDK 11 that comes pre installed in the Gitpod env.

dmatej commented 1 month ago

Interesting, so it is related to Oracle GraalVM or file system, because it doesn't fail with my Temurin 11 and 21 JDK and any Temurin in between. I remember we had to rewrite some tests which covered file locking that behaves absolutely differently on Linux and on Windows, and there was even some difference on Mac too. This looks quite good: https://stackoverflow.com/a/19877372/375449

Thihup commented 1 month ago

Tried with Temurin 21 and it failed with the same error. However, running df -T it showed that it is using XFS file system. I guess this should be related to this issue

Filesystem                               Type     1K-blocks      Used  Available Use% Mounted on
/.workspace/mark                         shiftfs 1467981316 322329780 1145651536  22% /
tmpfs                                    tmpfs        65536         0      65536   0% /dev
/dev/sda5                                xfs      463355884   9530676  453825208   3% /dev/termination-log
shm                                      tmpfs        65536         0      65536   0% /dev/shm
tmpfs                                    tmpfs     32920536         0   32920536   0% /sys/firmware
/dev/mapper/lvm--disk-gitpod--workspaces xfs       52428800   7369048   45059752  15% /workspace
/dev/mapper/lvm--disk-containerd--mount  xfs     1467981316 322329780 1145651536  22% /etc/hostname
tmpfs                                    tmpfs     32920536      1336   32919200   1% /tmp
tmpfs                                    tmpfs     32920536         0   32920536   0% /proc/acpi
tmpfs                                    tmpfs        65536         0      65536   0% /proc/keys
tmpfs                                    tmpfs     32920536         0   32920536   0% /proc/scsi
Thihup commented 1 month ago

It is comparing across two filesystems, XFS and TmpFS.

gitpod /workspace/glassfish (issue/25085) $ stat /workspace/glassfish/nucleus/common/common-util/target/test-classes/process
  File: /workspace/glassfish/nucleus/common/common-util/target/test-classes/process
  Size: 29              Blocks: 0          IO Block: 4096   directory
Device: fd01h/64769d    Inode: 2709531234  Links: 2
Access: (0755/drwxr-xr-x)  Uid: (33333/  gitpod)   Gid: (33333/  gitpod)
Access: 2024-08-13 11:51:15.424977819 +0000
Modify: 2024-08-13 11:51:15.424977819 +0000
Change: 2024-08-13 11:51:15.424977819 +0000
 Birth: 2024-08-13 11:51:15.424977819 +0000
gitpod /workspace/glassfish (issue/25085) $ stat /tmp/junit14905427492267933262/outputDir
  File: /tmp/junit14905427492267933262/outputDir
  Size: 60              Blocks: 0          IO Block: 4096   directory
Device: 100070h/1048688d        Inode: 3942        Links: 2
Access: (0755/drwxr-xr-x)  Uid: (33333/  gitpod)   Gid: (33333/  gitpod)
Access: 2024-08-13 12:03:07.572397212 +0000
Modify: 2024-08-13 12:03:07.572397212 +0000
Change: 2024-08-13 12:03:07.572397212 +0000
 Birth: 2024-08-13 12:03:07.572397212 +0000
Thihup commented 1 month ago

Forcing the tmp directory to be in the same file system (-Djava.io.tmpdir=/workspace/my-tmp/) works

gitpod /workspace/glassfish (issue/25085) $ stat  /workspace/my-tmp/junit16177679752619825247/outputDir
  File: /workspace/my-tmp/junit16177679752619825247/outputDir
  Size: 29              Blocks: 0          IO Block: 4096   directory
Device: fd01h/64769d    Inode: 2088763522  Links: 2
Access: (0755/drwxr-xr-x)  Uid: (33333/  gitpod)   Gid: (33333/  gitpod)
Access: 2024-08-13 12:11:56.279965133 +0000
Modify: 2024-08-13 12:11:56.283965129 +0000
Change: 2024-08-13 12:11:56.283965129 +0000
 Birth: 2024-08-13 12:11:56.279965133 +0000

However, now other test fails 🫠

[ERROR] Tests run: 9, Failures: 1, Errors: 0, Skipped: 1, Time elapsed: 1.911 s <<< FAILURE! -- in org.glassfish.common.util.admin.locking.FileLockTest
[ERROR] org.glassfish.common.util.admin.locking.FileLockTest.lockAndRenameTest -- Time elapsed: 0.006 s <<< FAILURE!
org.opentest4j.AssertionFailedError: File renaming blocked ==> expected: <true> but was: <false>
        at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
        at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
        at org.junit.jupiter.api.AssertTrue.failNotTrue(AssertTrue.java:63)
        at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:36)
        at org.junit.jupiter.api.Assertions.assertTrue(Assertions.java:214)
        at org.glassfish.common.util.admin.locking.FileLockTest.lockAndRenameTest(FileLockTest.java:364)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
dmatej commented 1 month ago

Yeah, and here we go with the locking test :-)