From 5e639164edace63c3973997c6bc7309be47c230c Mon Sep 17 00:00:00 2001 From: Jan Cizmar Date: Thu, 14 Dec 2023 19:35:23 +0100 Subject: [PATCH] fix: bypass the language stats listener in tests --- backend/app/src/test/resources/application.yaml | 2 +- .../kotlin/io/tolgee/component/CurrentDateProvider.kt | 9 +++++---- .../component/eventListeners/LanguageStatsListener.kt | 4 ++++ .../development/testDataBuilder/TestDataService.kt | 6 +++++- ee/backend/tests/src/test/resources/application.yaml | 2 +- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/backend/app/src/test/resources/application.yaml b/backend/app/src/test/resources/application.yaml index abc70effe9..4404906561 100644 --- a/backend/app/src/test/resources/application.yaml +++ b/backend/app/src/test/resources/application.yaml @@ -43,7 +43,7 @@ spring: tolgee: postgres-autostart: enabled: true - container-name: tolgee_backend_tests_postgres + container-name: tolgee_backend_tests_postgres_main port: 55433 stop: false data-path: ./build/test_data diff --git a/backend/data/src/main/kotlin/io/tolgee/component/CurrentDateProvider.kt b/backend/data/src/main/kotlin/io/tolgee/component/CurrentDateProvider.kt index 6af5631a7c..3637049eb1 100644 --- a/backend/data/src/main/kotlin/io/tolgee/component/CurrentDateProvider.kt +++ b/backend/data/src/main/kotlin/io/tolgee/component/CurrentDateProvider.kt @@ -14,6 +14,7 @@ import org.springframework.data.auditing.AuditingHandler import org.springframework.data.auditing.DateTimeProvider import org.springframework.stereotype.Component import org.springframework.transaction.PlatformTransactionManager +import java.sql.Timestamp import java.time.Duration import java.time.ZonedDateTime import java.time.format.DateTimeFormatter @@ -90,9 +91,9 @@ class CurrentDateProvider( ForcedServerDateTime::class.java ).resultList.singleOrNull() - private fun getForcedTime(): Date? = + private fun getForcedTime(): Timestamp? = entityManager.createNativeQuery( - "select st from forced_server_date_time st where st.id = 1", - Date::class.java - ).resultList.singleOrNull() as Date? + "select st from public.forced_server_date_time st where st.id = 1", + Timestamp::class.java + ).resultList.singleOrNull() as Timestamp? } diff --git a/backend/data/src/main/kotlin/io/tolgee/component/eventListeners/LanguageStatsListener.kt b/backend/data/src/main/kotlin/io/tolgee/component/eventListeners/LanguageStatsListener.kt index dd84130a1c..ebd8188e57 100644 --- a/backend/data/src/main/kotlin/io/tolgee/component/eventListeners/LanguageStatsListener.kt +++ b/backend/data/src/main/kotlin/io/tolgee/component/eventListeners/LanguageStatsListener.kt @@ -15,9 +15,13 @@ import org.springframework.transaction.event.TransactionalEventListener class LanguageStatsListener( private var languageStatsService: LanguageStatsService ) { + + var bypass = false + @TransactionalEventListener @Async fun onActivity(event: OnProjectActivityEvent) { + if (bypass) return runSentryCatching { val projectId = event.activityRevision.projectId ?: return diff --git a/backend/data/src/main/kotlin/io/tolgee/development/testDataBuilder/TestDataService.kt b/backend/data/src/main/kotlin/io/tolgee/development/testDataBuilder/TestDataService.kt index a7a2aea4c3..a8bb59f0f1 100644 --- a/backend/data/src/main/kotlin/io/tolgee/development/testDataBuilder/TestDataService.kt +++ b/backend/data/src/main/kotlin/io/tolgee/development/testDataBuilder/TestDataService.kt @@ -1,6 +1,7 @@ package io.tolgee.development.testDataBuilder import io.tolgee.activity.ActivityHolder +import io.tolgee.component.eventListeners.LanguageStatsListener import io.tolgee.development.testDataBuilder.builders.ImportBuilder import io.tolgee.development.testDataBuilder.builders.KeyBuilder import io.tolgee.development.testDataBuilder.builders.PatBuilder @@ -74,7 +75,8 @@ class TestDataService( private val bigMetaService: BigMetaService, private val activityHolder: ActivityHolder, private val automationService: AutomationService, - private val contentDeliveryConfigService: ContentDeliveryConfigService + private val contentDeliveryConfigService: ContentDeliveryConfigService, + private val languageStatsListener: LanguageStatsListener ) : Logging { @Transactional @@ -88,6 +90,7 @@ class TestDataService( @Transactional fun saveTestData(builder: TestDataBuilder) { activityHolder.enableAutoCompletion = false + languageStatsListener.bypass = true prepare() // Projects have to be stored in separate transaction since projectHolder's @@ -113,6 +116,7 @@ class TestDataService( updateLanguageStats(builder) activityHolder.enableAutoCompletion = true + languageStatsListener.bypass = false } @Transactional diff --git a/ee/backend/tests/src/test/resources/application.yaml b/ee/backend/tests/src/test/resources/application.yaml index 4a04524877..7b0f3ab515 100644 --- a/ee/backend/tests/src/test/resources/application.yaml +++ b/ee/backend/tests/src/test/resources/application.yaml @@ -36,7 +36,7 @@ spring: tolgee: postgres-autostart: enabled: true - container-name: tolgee_backend_tests_postgres + container-name: tolgee_backend_tests_postgres_main port: 55433 stop: false data-path: ./build/test_data