From db6fdba06563d8e5cb39ddaabec976f2db6a1448 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Wed, 24 Jun 2020 11:42:18 -0500 Subject: [PATCH] Fix unit test FP --- .../qualitygate/ProjectsInWarningDaemon.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/qualitygate/ProjectsInWarningDaemon.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/qualitygate/ProjectsInWarningDaemon.java index 15eb5b5768c..f1e5559c9d1 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/qualitygate/ProjectsInWarningDaemon.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/qualitygate/ProjectsInWarningDaemon.java @@ -40,7 +40,7 @@ import static org.sonar.api.measures.Metric.Level.WARN; /** * This class is regularly checking the number of projects in warning state, in order to not return the "Warning" value in the quality gate facet of the Projects page when there are no more projects in warning. - * + * * @see SONAR-12140 for more information */ public class ProjectsInWarningDaemon implements Startable { @@ -93,21 +93,22 @@ public class ProjectsInWarningDaemon implements Startable { private Runnable countProjectsInWarning() { return () -> { + long nbProjectsInWarning = projectMeasuresIndex.search( + new ProjectMeasuresQuery() + .setQualityGateStatus(WARN) + .setIgnoreAuthorization(true), + // We only need the number of projects in warning + new SearchOptions().setLimit(1)).getTotal(); + try (DbSession dbSession = dbClient.openSession(false)) { - long nbProjectsInWarning = projectMeasuresIndex.search( - new ProjectMeasuresQuery() - .setQualityGateStatus(WARN) - .setIgnoreAuthorization(true), - // We only need the number of projects in warning - new SearchOptions().setLimit(1)).getTotal(); - projectsInWarning.update(nbProjectsInWarning); updateProjectsInWarningInDb(dbSession, nbProjectsInWarning); - if (nbProjectsInWarning == 0L) { - LOG.info("Counting number of projects in warning will be disabled as there are no more projects in warning."); - executorService.shutdown(); - } } catch (Exception e) { - LOG.error("Error while counting number of projects in warning: {}", e); + LOG.error("Error updating number of projects in warning: {}", e); + } + projectsInWarning.update(nbProjectsInWarning); + if (nbProjectsInWarning == 0L) { + LOG.info("Counting number of projects in warning will be disabled as there are no more projects in warning."); + executorService.shutdown(); } }; } -- 2.39.5