]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-22159 Add assume check on creation date properly set in test cleanUpOld
authorMatteo Mara <matteo.mara@sonarsource.com>
Mon, 29 Apr 2024 09:11:41 +0000 (11:11 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 29 Apr 2024 20:02:42 +0000 (20:02 +0000)
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java

index 19a251859ae035fa73e02d6ece0fd20f1c8d7693..11a0959983977e79dec2e6c963f4880cfc72926a 100644 (file)
@@ -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.toPath(), creationTime);
     }
 
     tempFolderProvider.provide(
@@ -159,4 +161,15 @@ public class GlobalTempFolderProviderTest {
     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);
+  }
 }