Re: RFR: JDK-8327474 Review use of java.io.tmpdir in jdk tests [v2]
On Thu, 21 Mar 2024 15:06:58 GMT, Jaikiran Pai wrote: >> Bill Huang has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Implemented review comments > > test/jdk/java/util/zip/ZipFile/ZeroDate.java line 95: > >> 93: >> 94: // ensure that the archive is still readable, and the date is >> 1979-11-30 >> 95: Path path = Utils.createTempFile("out", ".zip"); > > So it looks like the test library has this utility method which allows to > create temporary files within the jtreg scratch directory. Perhaps we should > use it then. Having said that, is there a reason why one test method in this > test now uses `Files.createTempFile(...)` and this other test method uses > `Utils.createTempFile(...)`? Yes, you are right. We don't need explicit deletion for these files by using this util method, Utils.createTempFile. - PR Review Comment: https://git.openjdk.org/jdk/pull/18352#discussion_r1534290137
Re: RFR: JDK-8327474 Review use of java.io.tmpdir in jdk tests [v2]
On Thu, 21 Mar 2024 14:41:36 GMT, Jaikiran Pai wrote: >> Bill Huang has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Implemented review comments > > test/jdk/com/sun/management/HotSpotDiagnosticMXBean/CheckOrigin.java line 57: > >> 55: >> 56: File flagsFile = File.createTempFile("CheckOriginFlags", >> null); >> 57: flagsFile.deleteOnExit(); > > Hello Bill, jtreg uses a scratch directory when running tests. When a test is > launched, the current working directory points to the scratch directory for > the test that's currently executing. jtreg manages the lifecycle of scratch > directories and even cleans them up (as necessary). > Would it instead be better to just create the temporary file within the jtreg > scratch directory (represented by the current working directory)? That way > you could just do: > > > File flagsFile = Files.createTempFile(Path.of("."), "CheckOriginFlags", > null).toFile(); > > and don't need any explicit deletions? Hi Jaikiran, I think both solutions work for this bug. I personally prefer to place the files in the scratch directory for the ease of debugging. In addition, for this specific test, I am considering using File.createTempFile("CheckOriginaFlags", null, Path.of(".").toFile) instead of Files.createTempFile for consistency purposes, as Files.createTempFile may have more restrictive access permissions. - PR Review Comment: https://git.openjdk.org/jdk/pull/18352#discussion_r1534283105
Re: RFR: JDK-8327474 Review use of java.io.tmpdir in jdk tests [v2]
On Tue, 19 Mar 2024 17:58:46 GMT, Bill Huang wrote: >> This task addresses an essential aspect of our testing infrastructure: the >> proper handling and cleanup of temporary files and socket files created >> during test execution. The motivation behind these changes is to prevent the >> accumulation of unnecessary files in the default temporary directory, which >> can affect the system's storage and potentially influence subsequent test >> runs. >> >> Our review identified that several tests create temporary files or socket >> files without ensuring their removal post-execution. >> - Direct calls to java.io.File.createTempFile and >> java.nio.file.Files.createTempFile without adequate cleanup. >> - Tests using NIO socket channels with StandardProtocolFamily.UNIX, not >> explicitly removing socket files post-use. > > Bill Huang has updated the pull request incrementally with one additional > commit since the last revision: > > Implemented review comments test/jdk/java/util/zip/ZipFile/ZeroDate.java line 95: > 93: > 94: // ensure that the archive is still readable, and the date is > 1979-11-30 > 95: Path path = Utils.createTempFile("out", ".zip"); So it looks like the test library has this utility method which allows to create temporary files within the jtreg scratch directory. Perhaps we should use it then. Having said that, is there a reason why one test method in this test now uses `Files.createTempFile(...)` and this other test method uses `Utils.createTempFile(...)`? - PR Review Comment: https://git.openjdk.org/jdk/pull/18352#discussion_r1534105420
Re: RFR: JDK-8327474 Review use of java.io.tmpdir in jdk tests [v2]
On Tue, 19 Mar 2024 17:58:46 GMT, Bill Huang wrote: >> This task addresses an essential aspect of our testing infrastructure: the >> proper handling and cleanup of temporary files and socket files created >> during test execution. The motivation behind these changes is to prevent the >> accumulation of unnecessary files in the default temporary directory, which >> can affect the system's storage and potentially influence subsequent test >> runs. >> >> Our review identified that several tests create temporary files or socket >> files without ensuring their removal post-execution. >> - Direct calls to java.io.File.createTempFile and >> java.nio.file.Files.createTempFile without adequate cleanup. >> - Tests using NIO socket channels with StandardProtocolFamily.UNIX, not >> explicitly removing socket files post-use. > > Bill Huang has updated the pull request incrementally with one additional > commit since the last revision: > > Implemented review comments test/jdk/java/nio/channels/unixdomain/Bind.java line 201: > 199: System.out.println("Null server address: " + > server.getLocalAddress()); > 200: } finally { > 201: Files.deleteIfExists(usa.getPath()); `usa` can be `null` here, if it never got assigned due to some exception in the prior lines, which can lead to a `NullPointerException` here. test/jdk/java/nio/channels/unixdomain/Bind.java line 341: > 339: assertAddress(client.getRemoteAddress(), usa, "server"); > 340: } finally { > 341: Files.deleteIfExists(usa.getPath()); Same applies here about potential NullPointerException and some other places in other files as well. - PR Review Comment: https://git.openjdk.org/jdk/pull/18352#discussion_r1534092806 PR Review Comment: https://git.openjdk.org/jdk/pull/18352#discussion_r1534095046
Re: RFR: JDK-8327474 Review use of java.io.tmpdir in jdk tests [v2]
On Tue, 19 Mar 2024 17:58:46 GMT, Bill Huang wrote: >> This task addresses an essential aspect of our testing infrastructure: the >> proper handling and cleanup of temporary files and socket files created >> during test execution. The motivation behind these changes is to prevent the >> accumulation of unnecessary files in the default temporary directory, which >> can affect the system's storage and potentially influence subsequent test >> runs. >> >> Our review identified that several tests create temporary files or socket >> files without ensuring their removal post-execution. >> - Direct calls to java.io.File.createTempFile and >> java.nio.file.Files.createTempFile without adequate cleanup. >> - Tests using NIO socket channels with StandardProtocolFamily.UNIX, not >> explicitly removing socket files post-use. > > Bill Huang has updated the pull request incrementally with one additional > commit since the last revision: > > Implemented review comments test/jdk/com/sun/management/HotSpotDiagnosticMXBean/CheckOrigin.java line 57: > 55: > 56: File flagsFile = File.createTempFile("CheckOriginFlags", > null); > 57: flagsFile.deleteOnExit(); Hello Bill, jtreg uses a scratch directory when running tests. When a test is launched, the current working directory points to the scratch directory for the test that's currently executing. jtreg manages the lifecycle of scratch directories and even cleans them up (as necessary). Would it instead be better to just create the temporary file within the jtreg scratch directory (represented by the current working directory)? That way you could just do: File flagsFile = Files.createTempFile(Path.of("."), "CheckOriginFlags", null).toFile(); and don't need any explicit deletions? - PR Review Comment: https://git.openjdk.org/jdk/pull/18352#discussion_r1534054951
Re: RFR: JDK-8327474 Review use of java.io.tmpdir in jdk tests [v2]
On Tue, 19 Mar 2024 17:58:46 GMT, Bill Huang wrote: >> This task addresses an essential aspect of our testing infrastructure: the >> proper handling and cleanup of temporary files and socket files created >> during test execution. The motivation behind these changes is to prevent the >> accumulation of unnecessary files in the default temporary directory, which >> can affect the system's storage and potentially influence subsequent test >> runs. >> >> Our review identified that several tests create temporary files or socket >> files without ensuring their removal post-execution. >> - Direct calls to java.io.File.createTempFile and >> java.nio.file.Files.createTempFile without adequate cleanup. >> - Tests using NIO socket channels with StandardProtocolFamily.UNIX, not >> explicitly removing socket files post-use. > > Bill Huang has updated the pull request incrementally with one additional > commit since the last revision: > > Implemented review comments Speaking for JFR, we should probably just create a normal file, possibly with a filename to indicate subtest and iteration. That said, test changes for JFR looks fine, and fixing the filename is outside the scope of this bug. - PR Comment: https://git.openjdk.org/jdk/pull/18352#issuecomment-2009218768
Re: RFR: JDK-8327474 Review use of java.io.tmpdir in jdk tests [v2]
> This task addresses an essential aspect of our testing infrastructure: the > proper handling and cleanup of temporary files and socket files created > during test execution. The motivation behind these changes is to prevent the > accumulation of unnecessary files in the default temporary directory, which > can affect the system's storage and potentially influence subsequent test > runs. > > Our review identified that several tests create temporary files or socket > files without ensuring their removal post-execution. > - Direct calls to java.io.File.createTempFile and > java.nio.file.Files.createTempFile without adequate cleanup. > - Tests using NIO socket channels with StandardProtocolFamily.UNIX, not > explicitly removing socket files post-use. Bill Huang has updated the pull request incrementally with one additional commit since the last revision: Implemented review comments - Changes: - all: https://git.openjdk.org/jdk/pull/18352/files - new: https://git.openjdk.org/jdk/pull/18352/files/8472c31f..620f9259 Webrevs: - full: https://webrevs.openjdk.org/?repo=jdk=18352=01 - incr: https://webrevs.openjdk.org/?repo=jdk=18352=00-01 Stats: 136 lines in 5 files changed: 36 ins; 13 del; 87 mod Patch: https://git.openjdk.org/jdk/pull/18352.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/18352/head:pull/18352 PR: https://git.openjdk.org/jdk/pull/18352