Skip to content

Commit

Permalink
SONAR-22159 Add assume check on creation date properly set in test cl…
Browse files Browse the repository at this point in the history
…eanUpOld
  • Loading branch information
matteo-mara-sonarsource authored and sonartech committed Apr 29, 2024
1 parent 40102d6 commit 4603efa
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.FileTime;
import java.util.Collections;
Expand Down Expand Up @@ -70,6 +71,7 @@ public void cleanUpOld() throws IOException {
File tmp = new File(workingDir, ".sonartmp_" + i);
tmp.mkdirs();
setFileCreationDate(tmp, creationTime);
assumeCorrectFileCreationDate(tmp.toPath(), creationTime);
}

tempFolderProvider.provide(
Expand Down Expand Up @@ -159,4 +161,15 @@ private void setFileCreationDate(File f, long time) throws IOException {
FileTime creationTime = FileTime.fromMillis(time);
attributes.setTimes(creationTime, creationTime, creationTime);
}

// See SONAR-22159, the test started failing due to issues in setting the correct creation time on Cirrus, skipping the test if the problem
// happens
private void assumeCorrectFileCreationDate(Path tmp, long creationTime) throws IOException {
FileTime fileCreationTimeSet = Files.getFileAttributeView(tmp, BasicFileAttributeView.class).readAttributes().creationTime();
FileTime expectedCreationTime = FileTime.fromMillis(creationTime);

assumeTrue(String.format("Incorrect creation date set on temporary file %s: %s set instead of %s",
tmp.toAbsolutePath(), fileCreationTimeSet, expectedCreationTime),
expectedCreationTime.compareTo(fileCreationTimeSet) >= 0);
}
}

0 comments on commit 4603efa

Please sign in to comment.