]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12513 last used date is never set on new Quality Profiles
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 9 Oct 2019 10:47:08 +0000 (12:47 +0200)
committerSonarTech <sonartech@sonarsource.com>
Wed, 9 Oct 2019 18:21:07 +0000 (20:21 +0200)
all QP start with no last used date in the Database, which is represented by a null value in the column,
the update method ensures no update is done if new date is older than the current one
it does so by comparing the new date with the current value, however, this test always returns false if the current value is null

this way of updating the last used date was introduced to fix SONAR-10462 (Update of last used date on Quality Profile can fail with Deadlock on Postgres)
since then, last used date of new QP (which includes any new install of SQ since 7.8, including the LTS) is never set

server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java

index dcbdaefe4ea698c71c55cb03e5ec88820274680f..5a74720b17a49cd658e5459be021419900b9b220 100644 (file)
@@ -98,7 +98,7 @@
       updated_at = #{now, jdbcType=BIGINT}
     where
       uuid = #{uuid, jdbcType=VARCHAR}
-      and last_used &lt; #{lastUsedDate, jdbcType=BIGINT}
+      and (last_used is null or last_used &lt; #{lastUsedDate, jdbcType=BIGINT})
   </update>
 
   <delete id="deleteRuleProfilesByUuids" parameterType="String">
index b27df5e28cfee5835a7216caf5e129d1807f8b58..a05098c9525358f4a27fd60d5fccd7652d80a044 100644 (file)
@@ -149,7 +149,20 @@ public class QualityProfileDaoTest {
   }
 
   @Test
-  public void test_updateLastUsedDate() {
+  public void test_updateLastUsedDate_if_never_been_set_yet() {
+    QProfileDto initial = QualityProfileTesting.newQualityProfileDto()
+      .setLastUsed(null);
+    underTest.insert(dbSession, initial);
+
+    int count = underTest.updateLastUsedDate(dbSession, initial, 15_000L);
+
+    assertThat(count).isEqualTo(1);
+    QProfileDto reloaded = underTest.selectByUuid(dbSession, initial.getKee());
+    assertThat(reloaded.getLastUsed()).isEqualTo(15_000L);
+  }
+
+  @Test
+  public void test_updateLastUsedDate_if_more_recent() {
     QProfileDto initial = QualityProfileTesting.newQualityProfileDto()
       .setLastUsed(10_000L);
     underTest.insert(dbSession, initial);