From d17f0721a3a82e2f2b0fb424c8076159f9331bf0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Wed, 9 Oct 2019 12:47:08 +0200 Subject: [PATCH] SONAR-12513 last used date is never set on new Quality Profiles 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 --- .../db/qualityprofile/QualityProfileMapper.xml | 2 +- .../db/qualityprofile/QualityProfileDaoTest.java | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml index dcbdaefe4ea..5a74720b17a 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml @@ -98,7 +98,7 @@ updated_at = #{now, jdbcType=BIGINT} where uuid = #{uuid, jdbcType=VARCHAR} - and last_used < #{lastUsedDate, jdbcType=BIGINT} + and (last_used is null or last_used < #{lastUsedDate, jdbcType=BIGINT}) diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java index b27df5e28cf..a05098c9525 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java @@ -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); -- 2.39.5