]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-22159 Modify the way the creation date is set in junit test
authorMatteo Mara <matteo.mara@sonarsource.com>
Fri, 26 Apr 2024 13:47:02 +0000 (15:47 +0200)
committerMatteo Mara <matteo.mara@sonarsource.com>
Tue, 30 Apr 2024 08:59:02 +0000 (10:59 +0200)
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java

index 15ee7b69856b118792595f5d8c00ec2fc071826e..9d8522a897fd2b231cd63f92055388dbad6ad6e5 100644 (file)
@@ -67,6 +67,7 @@ class GlobalTempFolderProviderTest {
       Path tmp = workingDir.resolve(".sonartmp_" + i);
       Files.createDirectories(tmp);
       setFileCreationDate(tmp, creationTime);
+      assumeCorrectFileCreationDate(tmp, creationTime);
     }
 
     underTest.provide(
@@ -76,6 +77,16 @@ class GlobalTempFolderProviderTest {
     assertThat(workingDir.toFile().list()).hasSize(1);
   }
 
+  // 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(expectedCreationTime.compareTo(fileCreationTimeSet) >= 0,
+      String.format("Incorrect creation date set on temporary file %s: %s set instead of %s", tmp.toAbsolutePath(), fileCreationTimeSet, expectedCreationTime));
+  }
+
   @Test
   void createTempFolderFromSonarHome(@TempDir Path sonarUserHomePath) throws Exception {
     // with sonar home, it will be in {sonar.home}/.sonartmp