From 40fce5e9fec3776787bec8a50dfa7a43eb15c8bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20S=C5=82abek?= Date: Fri, 22 Nov 2024 15:21:38 +0100 Subject: [PATCH 1/6] add test start logger --- build.sbt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index fbaf1a8e2fa..ab7f977d297 100644 --- a/build.sbt +++ b/build.sbt @@ -1,5 +1,6 @@ import com.typesafe.sbt.packager.SettingsHelper import com.typesafe.sbt.packager.docker.DockerPlugin.autoImport.dockerUsername +import org.slf4j.LoggerFactory import pl.project13.scala.sbt.JmhPlugin import pl.project13.scala.sbt.JmhPlugin._ import sbt.Keys._ @@ -160,6 +161,14 @@ def forScalaVersion[T](version: String)(provide: PartialFunction[(Int, Int), T]) } } +lazy val testGroupStartLogger = new TestReportListener { + private val logger = LoggerFactory.getLogger("TestListener") + override def startGroup(name: String): Unit = logger.error(s"Starting test group [$name]") + override def testEvent(event: TestEvent): Unit = () + override def endGroup(name: String, t: Throwable): Unit = () + override def endGroup(name: String, result: TestResult): Unit = () +} + lazy val commonSettings = publishSettings ++ Seq( @@ -170,7 +179,12 @@ lazy val commonSettings = "confluent" at "https://packages.confluent.io/maven", ), // We ignore k8s tests to keep development setup low-dependency - Test / testOptions ++= Seq(scalaTestReports, ignoreSlowTests, ignoreExternalDepsTests), + Test / testOptions ++= Seq( + scalaTestReports, + ignoreSlowTests, + ignoreExternalDepsTests, + Tests.Listeners(List(testGroupStartLogger)) + ), addCompilerPlugin("org.typelevel" % "kind-projector" % "0.13.3" cross CrossVersion.full), libraryDependencies += compilerPlugin( "com.github.ghik" % "silencer-plugin" % forScalaVersion(scalaVersion.value) { From 085d8031cb2cb9fb59a76bf74286ebd7bb102c7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20S=C5=82abek?= Date: Tue, 26 Nov 2024 16:03:55 +0100 Subject: [PATCH 2/6] logging in flaky test --- .../pl/touk/nussknacker/test/base/it/NuResourcesTest.scala | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/designer/server/src/test/scala/pl/touk/nussknacker/test/base/it/NuResourcesTest.scala b/designer/server/src/test/scala/pl/touk/nussknacker/test/base/it/NuResourcesTest.scala index cde22f36654..cfef30ce1c1 100644 --- a/designer/server/src/test/scala/pl/touk/nussknacker/test/base/it/NuResourcesTest.scala +++ b/designer/server/src/test/scala/pl/touk/nussknacker/test/base/it/NuResourcesTest.scala @@ -245,7 +245,12 @@ trait NuResourcesTest testCode: => Assertion ): Assertion = createProcessRequest(process.name) { _ => + // FIXME: sometimes this cant be decoded + logger.error( + s"FLAKY TEST PROBLEM in test `snapshots process` ---- decoded json: ${parser.decode[Json](responseAs[String]).toString}" + ) val json = parser.decode[Json](responseAs[String]).rightValue + logger.error(json.toString) val resp = CreateProcessResponse(json) resp.processName shouldBe process.name From b1521c0efbd339b29ec0448dc841a221c8ee1b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20S=C5=82abek?= Date: Tue, 26 Nov 2024 16:08:06 +0100 Subject: [PATCH 3/6] try to fix periodic test --- .../PeriodicProcessServiceIntegrationTest.scala | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/engine/flink/management/periodic/src/test/scala/pl/touk/nussknacker/engine/management/periodic/PeriodicProcessServiceIntegrationTest.scala b/engine/flink/management/periodic/src/test/scala/pl/touk/nussknacker/engine/management/periodic/PeriodicProcessServiceIntegrationTest.scala index 0fd79cd3c06..889b47a577f 100644 --- a/engine/flink/management/periodic/src/test/scala/pl/touk/nussknacker/engine/management/periodic/PeriodicProcessServiceIntegrationTest.scala +++ b/engine/flink/management/periodic/src/test/scala/pl/touk/nussknacker/engine/management/periodic/PeriodicProcessServiceIntegrationTest.scala @@ -13,6 +13,7 @@ import org.scalatest.concurrent.ScalaFutures import org.scalatest.exceptions.TestFailedException import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers +import org.scalatest.time.{Millis, Seconds, Span} import org.testcontainers.utility.DockerImageName import pl.touk.nussknacker.engine.api.deployment.simple.SimpleStateStatus import pl.touk.nussknacker.engine.api.deployment.simple.SimpleStateStatus.ProblemStateStatus @@ -428,9 +429,12 @@ class PeriodicProcessServiceIntegrationTest toDeployAfterFinish should have length 1 toDeployAfterFinish.head.scheduleName.value.value shouldBe secondSchedule - val activities = service.getScenarioActivitiesSpecificToPeriodicProcess(processIdWithName).futureValue - val firstActivity = activities.head.asInstanceOf[ScenarioActivity.PerformedScheduledExecution] - activities shouldBe List( + val firstActivity = eventually { + val result = service.getScenarioActivitiesSpecificToPeriodicProcess(processIdWithName).futureValue + result should not be empty + result.head.asInstanceOf[ScenarioActivity.PerformedScheduledExecution] + } + firstActivity shouldBe ScenarioActivity.PerformedScheduledExecution( scenarioId = ScenarioId(1), scenarioActivityId = firstActivity.scenarioActivityId, @@ -443,8 +447,7 @@ class PeriodicProcessServiceIntegrationTest createdAt = firstActivity.createdAt, retriesLeft = None, nextRetryAt = None - ), - ) + ) } it should "handle multiple one time schedules" in withFixture() { f => From cac0d67d12ca54a52f8c81c298447fb6820483b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20S=C5=82abek?= Date: Tue, 26 Nov 2024 16:09:25 +0100 Subject: [PATCH 4/6] try to fix kafka test not waiting for created topic --- .../nussknacker/engine/kafka/KafkaClient.scala | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/utils/kafka-test-utils/src/main/scala/pl/touk/nussknacker/engine/kafka/KafkaClient.scala b/utils/kafka-test-utils/src/main/scala/pl/touk/nussknacker/engine/kafka/KafkaClient.scala index f03f23002ee..e3229fefdd3 100644 --- a/utils/kafka-test-utils/src/main/scala/pl/touk/nussknacker/engine/kafka/KafkaClient.scala +++ b/utils/kafka-test-utils/src/main/scala/pl/touk/nussknacker/engine/kafka/KafkaClient.scala @@ -7,13 +7,12 @@ import org.apache.kafka.clients.admin.{NewTopic, TopicDescription} import org.apache.kafka.clients.consumer.KafkaConsumer import org.apache.kafka.clients.producer.{Callback, KafkaProducer, ProducerRecord, RecordMetadata} import org.apache.kafka.common.header.Headers -import retry.When import java.time.Duration import java.util import java.util.{Collections, UUID} import scala.concurrent.ExecutionContext.Implicits.global -import scala.concurrent.{Future, Promise} +import scala.concurrent.{Await, Future, Promise} import scala.jdk.CollectionConverters._ import scala.util.{Failure, Success, Try} import scala.concurrent.duration._ @@ -33,12 +32,15 @@ class KafkaClient(kafkaAddress: String, id: String) extends LazyLogging { def createTopic(name: String, partitions: Int = 5): Unit = { adminClient.createTopics(Collections.singletonList(new NewTopic(name, partitions, 1: Short))).all().get() // When kraft enabled, topics doesn't appear instantly after createTopic - retry.Pause(10, 1.second)(Timer.default)( - Future { - topic(name) - } + val maxTime = 10.seconds + Await.result( + retry.Pause(10, 1.second)(Timer.default)( + Future { + topic(name) + } + ), + maxTime ) - } def deleteTopic(name: String): Unit = From 21bad8d6885a7f9131e83041294bdf4674e79b25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20S=C5=82abek?= Date: Tue, 26 Nov 2024 23:05:04 +0100 Subject: [PATCH 5/6] revert temp changes --- build.sbt | 16 +--------------- .../test/base/it/NuResourcesTest.scala | 5 ----- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/build.sbt b/build.sbt index ab7f977d297..fbaf1a8e2fa 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,5 @@ import com.typesafe.sbt.packager.SettingsHelper import com.typesafe.sbt.packager.docker.DockerPlugin.autoImport.dockerUsername -import org.slf4j.LoggerFactory import pl.project13.scala.sbt.JmhPlugin import pl.project13.scala.sbt.JmhPlugin._ import sbt.Keys._ @@ -161,14 +160,6 @@ def forScalaVersion[T](version: String)(provide: PartialFunction[(Int, Int), T]) } } -lazy val testGroupStartLogger = new TestReportListener { - private val logger = LoggerFactory.getLogger("TestListener") - override def startGroup(name: String): Unit = logger.error(s"Starting test group [$name]") - override def testEvent(event: TestEvent): Unit = () - override def endGroup(name: String, t: Throwable): Unit = () - override def endGroup(name: String, result: TestResult): Unit = () -} - lazy val commonSettings = publishSettings ++ Seq( @@ -179,12 +170,7 @@ lazy val commonSettings = "confluent" at "https://packages.confluent.io/maven", ), // We ignore k8s tests to keep development setup low-dependency - Test / testOptions ++= Seq( - scalaTestReports, - ignoreSlowTests, - ignoreExternalDepsTests, - Tests.Listeners(List(testGroupStartLogger)) - ), + Test / testOptions ++= Seq(scalaTestReports, ignoreSlowTests, ignoreExternalDepsTests), addCompilerPlugin("org.typelevel" % "kind-projector" % "0.13.3" cross CrossVersion.full), libraryDependencies += compilerPlugin( "com.github.ghik" % "silencer-plugin" % forScalaVersion(scalaVersion.value) { diff --git a/designer/server/src/test/scala/pl/touk/nussknacker/test/base/it/NuResourcesTest.scala b/designer/server/src/test/scala/pl/touk/nussknacker/test/base/it/NuResourcesTest.scala index cfef30ce1c1..cde22f36654 100644 --- a/designer/server/src/test/scala/pl/touk/nussknacker/test/base/it/NuResourcesTest.scala +++ b/designer/server/src/test/scala/pl/touk/nussknacker/test/base/it/NuResourcesTest.scala @@ -245,12 +245,7 @@ trait NuResourcesTest testCode: => Assertion ): Assertion = createProcessRequest(process.name) { _ => - // FIXME: sometimes this cant be decoded - logger.error( - s"FLAKY TEST PROBLEM in test `snapshots process` ---- decoded json: ${parser.decode[Json](responseAs[String]).toString}" - ) val json = parser.decode[Json](responseAs[String]).rightValue - logger.error(json.toString) val resp = CreateProcessResponse(json) resp.processName shouldBe process.name From d57db70a9896d76a8b75c7176d17520a8b81406b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20S=C5=82abek?= Date: Wed, 27 Nov 2024 11:05:13 +0100 Subject: [PATCH 6/6] rename --- .../scala/pl/touk/nussknacker/engine/kafka/KafkaClient.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/kafka-test-utils/src/main/scala/pl/touk/nussknacker/engine/kafka/KafkaClient.scala b/utils/kafka-test-utils/src/main/scala/pl/touk/nussknacker/engine/kafka/KafkaClient.scala index e3229fefdd3..63889dacfd0 100644 --- a/utils/kafka-test-utils/src/main/scala/pl/touk/nussknacker/engine/kafka/KafkaClient.scala +++ b/utils/kafka-test-utils/src/main/scala/pl/touk/nussknacker/engine/kafka/KafkaClient.scala @@ -32,14 +32,14 @@ class KafkaClient(kafkaAddress: String, id: String) extends LazyLogging { def createTopic(name: String, partitions: Int = 5): Unit = { adminClient.createTopics(Collections.singletonList(new NewTopic(name, partitions, 1: Short))).all().get() // When kraft enabled, topics doesn't appear instantly after createTopic - val maxTime = 10.seconds + val timeout = 10.seconds Await.result( retry.Pause(10, 1.second)(Timer.default)( Future { topic(name) } ), - maxTime + timeout ) }