aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatteo Mara <matteo.mara@sonarsource.com>2024-04-26 15:47:02 +0200
committersonartech <sonartech@sonarsource.com>2024-05-15 20:02:38 +0000
commit67e5e8d00426754ac29baa71b542282dd94d23d6 (patch)
tree7ebd81acf7139e55a7d7b7851139564243d0381d
parent6f44d61ec0a4e21985d0b90edfc41464d7081551 (diff)
downloadsonarqube-67e5e8d00426754ac29baa71b542282dd94d23d6.tar.gz
sonarqube-67e5e8d00426754ac29baa71b542282dd94d23d6.zip
SONAR-22159 Add assume check on creation date properly set in test cleanUpOld
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java13
1 files changed, 13 insertions, 0 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java
index 19a251859ae..b50ea725767 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java
@@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableMap;
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;
@@ -70,6 +71,7 @@ public class GlobalTempFolderProviderTest {
File tmp = new File(workingDir, ".sonartmp_" + i);
tmp.mkdirs();
setFileCreationDate(tmp, creationTime);
+ assumeCorrectFileCreationDate(tmp, creationTime);
}
tempFolderProvider.provide(
@@ -80,6 +82,17 @@ public class GlobalTempFolderProviderTest {
FileUtils.deleteQuietly(workingDir);
}
+ // 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(File tmp, long creationTime) throws IOException {
+ Path tmpFilePath = tmp.toPath();
+ FileTime fileCreationTimeSet = Files.getFileAttributeView(tmpFilePath, 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", tmpFilePath.toAbsolutePath(), fileCreationTimeSet, expectedCreationTime),
+ expectedCreationTime.compareTo(fileCreationTimeSet) >= 0);
+ }
+
@Test
public void createTempFolderSonarHome() throws Exception {
// with sonar home, it will be in {sonar.home}/.sonartmp