]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12140 Improve stability by reducing thread sleep in unit test
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 28 Jun 2019 15:09:56 +0000 (17:09 +0200)
committerSonarTech <sonartech@sonarsource.com>
Fri, 28 Jun 2019 18:21:13 +0000 (20:21 +0200)
server/sonar-server/src/main/java/org/sonar/server/qualitygate/ProjectsInWarningDaemon.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ProjectsInWarningDaemonTest.java

index 98c023e2700cbf584023530d64c26e489d30714d..01e9978e0d006433792e90174b0577e0088b28d9 100644 (file)
@@ -49,8 +49,8 @@ public class ProjectsInWarningDaemon implements Startable {
 
   private static final Logger LOG = Loggers.get(ProjectsInWarningDaemon.class);
 
-  private static final String FREQUENCY_IN_SECONDS_PROPERTY = "sonar.projectsInWarning.frequencyInSeconds";
-  private static final int DEFAULT_FREQUENCY_IN_SECONDS = 60 * 60 * 24;
+  private static final String FREQUENCY_IN_MILLISECONDS_PROPERTY = "sonar.projectsInWarning.frequencyInMilliseconds";
+  private static final int DEFAULT_FREQUENCY_IN_MILLISECONDS = 1000 * 60 * 60 * 24;
   private static final String THREAD_NAME_PREFIX = "sq-projects-in-warning-service-";
 
   private static final String LOCK_NAME = "ProjectsInWarn";
@@ -84,11 +84,11 @@ public class ProjectsInWarningDaemon implements Startable {
     }
     LOG.info("Counting number of projects in warning is enabled.");
     executorService = Executors.newSingleThreadScheduledExecutor(newThreadFactory());
-    executorService.scheduleWithFixedDelay(countProjectsInWarning(), 0, frequency(), TimeUnit.SECONDS);
+    executorService.scheduleWithFixedDelay(countProjectsInWarning(), 0, frequency(), TimeUnit.MILLISECONDS);
   }
 
   private int frequency() {
-    return config.getInt(FREQUENCY_IN_SECONDS_PROPERTY).orElse(DEFAULT_FREQUENCY_IN_SECONDS);
+    return config.getInt(FREQUENCY_IN_MILLISECONDS_PROPERTY).orElse(DEFAULT_FREQUENCY_IN_MILLISECONDS);
   }
 
   private Runnable countProjectsInWarning() {
index 5dfc66cef16785c8cc85c8dc75c04e88f6f7b099..ba56ae7b267a55c0c89ae0e164d042a873d045e9 100644 (file)
@@ -72,7 +72,7 @@ public class ProjectsInWarningDaemonTest {
 
   @Before
   public void setUp() throws Exception {
-    settings.setProperty("sonar.projectsInWarning.frequencyInSeconds", "1");
+    settings.setProperty("sonar.projectsInWarning.frequencyInMilliseconds", "100");
   }
 
   @After
@@ -139,7 +139,6 @@ public class ProjectsInWarningDaemonTest {
   public void update_internal_properties_when_already_exits_and_projects_in_warnings_more_than_zero() throws InterruptedException {
     allowLockToBeAcquired();
     MetricDto qualityGateStatus = insertQualityGateStatusMetric();
-    ;
     insertProjectInWarning(qualityGateStatus);
     insertProjectInWarning(qualityGateStatus);
     // Setting contains 10, it should be updated with new value
@@ -194,7 +193,7 @@ public class ProjectsInWarningDaemonTest {
   }
 
   private void waitForValueToBeComputed(long expectedValue) throws InterruptedException {
-    for (int i = 0; i < 100; i++) {
+    for (int i = 0; i < 1000; i++) {
       if (projectsInWarning.isInitialized() && projectsInWarning.count() == expectedValue) {
         break;
       }