Skip to content

Commit

Permalink
less strict write-only test (#820)
Browse files Browse the repository at this point in the history
Co-authored-by: Armin Samii <[email protected]>
  • Loading branch information
artoonie and artoonie authored May 1, 2024
1 parent 37fbe84 commit c02463b
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/test/java/network/brightspots/rcv/TabulatorTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,22 @@ private static void cleanOutputFolder(TabulatorSession session) {
if (!file.isDirectory()) {
try {
// Every ephemeral file must be set to read-only on close, including audit logs
assertFalse(
file.canWrite(),
"File must not be writeable: %s".formatted(file.getAbsolutePath()));
// Then set it writeable so it can be deleted
if (file.canWrite()) {
// If a previous test was exited early by a developer, the file may still be
// writeable. That makes it pretty annoying for developers to see these spurious
// failures. As a safeguard, we'll only check for writeability for files
// created in the last five minutes -- well over the duration of any test we
// have today.
if (file.lastModified() > System.currentTimeMillis() - 1000 * 60 * 5) {
fail("File must not be writeable: %s".formatted(file.getAbsolutePath()));
} else {
Logger.warning(
"File was writeable, but it was created more than five minutes ago"
+ " so we assume a previous test failed to clean it up: %s",
file.getAbsolutePath());
}
}
// Ensure it can be deleted -- make it writeable now.
boolean writeableSucceeded = file.setWritable(true);
if (!writeableSucceeded) {
Logger.warning("Failed to set file to writeable: %s", file.getAbsolutePath());
Expand Down

0 comments on commit c02463b

Please sign in to comment.