Ticket #1635 (closed defect: fixed)

Opened 6 years ago

Last modified 6 years ago

UpdaterTest unit tests fail, Windows

Reported by: aivar Owned by: dscho
Priority: major Milestone: imagej2-b7-ndim-data
Component: Updater Version:
Severity: serious Keywords:
Cc: Blocked By:
Blocking: #1901

Description

I'm trying to build ImageJ2 in NetBeans, Windows 8 64-bit. I patched some errors in ClassUtilsTest, AppUtilsTest, and FileUtilsTest (see 'windows' branch.) However now I'm getting 15 failures 1 error from 30 tests in UpdaterTest.

Attachments

UpdaterTest.txt Download (43.8 KB) - added by aivar 6 years ago.
Test results

Change History

Changed 6 years ago by aivar

Test results

comment:1 Changed 6 years ago by aivar

The most worrisome thing I am seeing is that things like "assertTrue(new File(ijRoot, "jars/egads-0.1.jar").delete());" are failing. For some reason files are not being deleted immediately. A poor workaround would be to use "deleteOnExit()".

comment:2 Changed 6 years ago by aivar

Possibly related:

 http://stackoverflow.com/questions/8097067/java-6-file-deletion
 http://stackoverflow.com/questions/991489/i-cant-delete-a-file-in-java

A much-simplified version succeeds in the assertion:

"

final File tmp = File.createTempFile("tmp", ".txt");
final FileOutputStream out = new FileOutputStream(tmp);
out.close();
assertTrue(tmp.delete);

"

Last edited 6 years ago by aivar (previous) (diff)

comment:3 Changed 6 years ago by aivar

Same issues happen in a Windows 7 VM. Generally related to the discussion at:

 http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4722539 "File.delete() doesn't work the same between Windows & Unix"

"We cannot fix this, for the same reasons that we cannot fix 4045014: There's no
efficient way to force Windows-style semantics on Unix, and vice-versa. This
difference is annoying, but it's not a violation of WORA because the
specification doesn't make any guarantees about what happens when you delete an
open file."

Windows won't delete files with an open handle and it won't delete a file that doesn't exist.

Some say the Java 7 NIO.2 classes offer improved file deletion.

comment:4 Changed 6 years ago by dscho

So is the file still in use? Then this is the bug.

comment:5 Changed 6 years ago by aivar

Yes. The platform-specific issue is that Windows is more rigorous about locking files.

Last edited 6 years ago by aivar (previous) (diff)

comment:6 Changed 6 years ago by aivar

Another platform-specific issue:

Under Windows 'assertTrue(new File(ijRoot, "blah").delete());', where "blah" is a new file name, fails; under OS X this succeeds.

Workaround for Windows is:

File blah = new File(ijRoot, "blah");
if (blah.exists) {

assertTrue(blah.delete());

}

comment:7 Changed 6 years ago by dscho

As to the locking: have you identified which files are still locked? We should get them unlocked before deleting them.

As to the deleting non-existent files: have you identified which files those are? We should not try to delete them.

comment:8 Changed 6 years ago by aivar

  • Summary changed from UpdaterTest unit tests fail, Windows 8 to UpdaterTest unit tests fail, Windows

comment:9 Changed 6 years ago by aivar

Locking was due to not explicitly closing JarFiles. They would get closed in the finalizer.

The "deleting non-existent files" issue doesn't actually happen in the build; it's just something else I came upon while debugging and thought I'd preserve a note here.

comment:10 Changed 6 years ago by bdezonia

  • Status changed from new to reviewing

dscho, please associated with some feature ticket

comment:11 Changed 6 years ago by dscho

  • Blocking 1347 added

comment:12 Changed 6 years ago by dscho

aivar, can you make your changes available as a pull request that merges cleanly with 'master', please? Otherwise I'll be forced to redo the fixes and retroactively waste the work hours you spent on this issue.

comment:13 Changed 6 years ago by dscho

  • Status changed from reviewing to closed
  • Resolution set to fixed

Fixed it myself in aad7221b38a588da809325adebff15f39f399412.

comment:14 Changed 6 years ago by bdezonia

  • Blocking 1901 added; 1347 removed
Note: See TracTickets for help on using tickets.