Skip to content

Commit

Permalink
fix: bypass the language stats listener in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCizmar committed Dec 14, 2023
1 parent afb9c99 commit 5e63916
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion backend/app/src/test/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -113,6 +116,7 @@ class TestDataService(

updateLanguageStats(builder)
activityHolder.enableAutoCompletion = true
languageStatsListener.bypass = false
}

@Transactional
Expand Down
2 changes: 1 addition & 1 deletion ee/backend/tests/src/test/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5e63916

Please sign in to comment.