aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>2023-02-13 17:42:48 +0100
committersonartech <sonartech@sonarsource.com>2023-02-16 20:02:43 +0000
commit1886a1601a494ae2e2802aaf7842d08d6a92369b (patch)
tree6d5fd7ea4411a089dcf7988d9d284c333f46130a
parentbe1b41a987cf329ec59a1fa59e39ee6ea86b09df (diff)
downloadsonarqube-1886a1601a494ae2e2802aaf7842d08d6a92369b.tar.gz
sonarqube-1886a1601a494ae2e2802aaf7842d08d6a92369b.zip
SONAR-18386 Add ANALYZE to test to avoid timeout on purge audit
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/audit/AuditDaoTest.java20
1 files changed, 20 insertions, 0 deletions
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/audit/AuditDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/audit/AuditDaoTest.java
index 64f9de0d3a2..25d42633dc0 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/audit/AuditDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/audit/AuditDaoTest.java
@@ -19,6 +19,8 @@
*/
package org.sonar.db.audit;
+import java.sql.SQLException;
+import java.sql.Statement;
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
@@ -26,6 +28,7 @@ import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.core.util.UuidFactoryImpl;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.dialect.PostgreSql;
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
@@ -62,6 +65,14 @@ public class AuditDaoTest {
@Test
public void purge_has_limit() {
prepareRowsWithDeterministicCreatedAt(100_001);
+ //SONAR-18386 In order to prevent database to hang forever, we let it digest the inserted data
+ if (db.getDbClient().getDatabase().getDialect().getId().equals(PostgreSql.ID)) {
+ try (Statement statement = db.getSession().getSqlSession().getConnection().createStatement()) {
+ statement.execute("ANALYZE audits");
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
long purged = testAuditDao.deleteBefore(dbSession, 200_000);
assertThat(purged).isEqualTo(100_000);
assertThat(db.countRowsOfTable(dbSession, "audits")).isOne();
@@ -73,6 +84,14 @@ public class AuditDaoTest {
@Test
public void purge_with_threshold() {
prepareRowsWithDeterministicCreatedAt(100_000);
+ //SONAR-18386 In order to prevent database to hang forever, we let it digest the inserted data
+ if (db.getDbClient().getDatabase().getDialect().getId().equals(PostgreSql.ID)) {
+ try (Statement statement = db.getSession().getSqlSession().getConnection().createStatement()) {
+ statement.execute("ANALYZE audits");
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
long purged = testAuditDao.deleteBefore(dbSession, 50_000);
assertThat(purged).isEqualTo(49_999);
assertThat(db.countRowsOfTable(dbSession, "audits")).isEqualTo(50_001);
@@ -141,5 +160,6 @@ public class AuditDaoTest {
AuditDto auditDto = AuditTesting.newAuditDto(i);
testAuditDao.insert(dbSession, auditDto);
}
+ dbSession.commit();
}
}