Skip to content

Commit

Permalink
add UT
Browse files Browse the repository at this point in the history
  • Loading branch information
wrzontek committed Jul 4, 2024
1 parent 1917cbd commit 6789f73
Showing 1 changed file with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,31 @@ package pl.touk.nussknacker.engine.management.periodic

import akka.actor.{Actor, ActorSystem, Props}
import akka.testkit.TestKit
import com.typesafe.scalalogging.LazyLogging
import org.scalatest.BeforeAndAfterAll
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike

class UtilsSpec extends TestKit(ActorSystem("UtilsSpec")) with AnyWordSpecLike with Matchers with BeforeAndAfterAll {
class UtilsSpec
extends TestKit(ActorSystem("UtilsSpec"))
with AnyWordSpecLike
with Matchers
with BeforeAndAfterAll
with LazyLogging {

override def afterAll(): Unit = {
TestKit.shutdownActorSystem(system)
}

"Utils" should {

"gracefully stop actor and free actor path" in {
"stop actor and free actor path" in {
class TestActor extends Actor {
override def receive: Receive = { case _ =>
()
}
}
val actorName = "actorName"
val actorName = "actorName1"

val actorRef = system.actorOf(Props(new TestActor), actorName)

Expand All @@ -30,6 +36,31 @@ class UtilsSpec extends TestKit(ActorSystem("UtilsSpec")) with AnyWordSpecLike w
system.actorOf(Props(new TestActor), actorName)
}

"stop actor and free actor path without waiting for all of it's messages to be processed" in {
class TestActor extends Actor {
override def receive: Receive = { case msg =>
logger.info(s"Sleeping on the job '$msg' ...")
Thread.sleep(1000)
}
}
val actorName =
"actorName2" // has to be different from the previous test, because the actor created at the end of that can still live

val actorRef = system.actorOf(Props(new TestActor), actorName)

var messageCounter = 0
while (messageCounter < 1000) {
actorRef ! s"message number $messageCounter"
messageCounter += 1
}

Thread.sleep(1000)
// with gracefulStop this times out, because the PoisonPill is queued after the many normal messages
Utils.stopActorAndWaitUntilItsNameIsFree(actorRef, system)

system.actorOf(Props(new TestActor), actorName)

Check failure on line 61 in engine/flink/management/periodic/src/test/scala/pl/touk/nussknacker/engine/management/periodic/UtilsSpec.scala

View workflow job for this annotation

GitHub Actions / REPORT-BackendTests-2.12

pl.touk.nussknacker.engine.management.periodic.UtilsSpec ► Utils should stop actor and free actor path without waiting for all of it's messages to be processed

Failed test found in: engine/flink/management/periodic/target/test-reports/TEST-pl.touk.nussknacker.engine.management.periodic.UtilsSpec.xml Error: akka.actor.InvalidActorNameException: actor name [actorName2] is not unique!
Raw output
akka.actor.InvalidActorNameException: actor name [actorName2] is not unique!
	at akka.actor.dungeon.ChildrenContainer$TerminatingChildrenContainer.reserve(ChildrenContainer.scala:198)
	at akka.actor.dungeon.Children.reserveChild(Children.scala:146)
	at akka.actor.dungeon.Children.reserveChild$(Children.scala:144)
	at akka.actor.ActorCell.reserveChild(ActorCell.scala:410)
	at akka.actor.dungeon.Children.makeChild(Children.scala:299)
	at akka.actor.dungeon.Children.attachChild(Children.scala:52)
	at akka.actor.dungeon.Children.attachChild$(Children.scala:51)
	at akka.actor.ActorCell.attachChild(ActorCell.scala:410)
	at akka.actor.ActorSystemImpl.actorOf(ActorSystem.scala:899)
	at pl.touk.nussknacker.engine.management.periodic.UtilsSpec.$anonfun$new$5(UtilsSpec.scala:61)
	at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
	at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
	at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
	at org.scalatest.Transformer.apply(Transformer.scala:22)
	at org.scalatest.Transformer.apply(Transformer.scala:20)
	at org.scalatest.wordspec.AnyWordSpecLike$$anon$3.apply(AnyWordSpecLike.scala:1240)
	at org.scalatest.TestSuite.withFixture(TestSuite.scala:196)
	at org.scalatest.TestSuite.withFixture$(TestSuite.scala:195)
	at pl.touk.nussknacker.engine.management.periodic.UtilsSpec.withFixture(UtilsSpec.scala:10)
	at org.scalatest.wordspec.AnyWordSpecLike.invokeWithFixture$1(AnyWordSpecLike.scala:1238)
	at org.scalatest.wordspec.AnyWordSpecLike.$anonfun$runTest$1(AnyWordSpecLike.scala:1250)
	at org.scalatest.SuperEngine.runTestImpl(Engine.scala:306)
	at org.scalatest.wordspec.AnyWordSpecLike.runTest(AnyWordSpecLike.scala:1250)
	at org.scalatest.wordspec.AnyWordSpecLike.runTest$(AnyWordSpecLike.scala:1232)
	at pl.touk.nussknacker.engine.management.periodic.UtilsSpec.runTest(UtilsSpec.scala:10)
	at org.scalatest.wordspec.AnyWordSpecLike.$anonfun$runTests$1(AnyWordSpecLike.scala:1309)
	at org.scalatest.SuperEngine.$anonfun$runTestsInBranch$1(Engine.scala:413)
	at scala.collection.immutable.List.foreach(List.scala:392)
	at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:401)
	at org.scalatest.SuperEngine.runTestsInBranch(Engine.scala:390)
	at org.scalatest.SuperEngine.$anonfun$runTestsInBranch$1(Engine.scala:427)
	at scala.collection.immutable.List.foreach(List.scala:392)
	at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:401)
	at org.scalatest.SuperEngine.runTestsInBranch(Engine.scala:396)
	at org.scalatest.SuperEngine.runTestsImpl(Engine.scala:475)
	at org.scalatest.wordspec.AnyWordSpecLike.runTests(AnyWordSpecLike.scala:1309)
	at org.scalatest.wordspec.AnyWordSpecLike.runTests$(AnyWordSpecLike.scala:1308)
	at pl.touk.nussknacker.engine.management.periodic.UtilsSpec.runTests(UtilsSpec.scala:10)
	at org.scalatest.Suite.run(Suite.scala:1114)
	at org.scalatest.Suite.run$(Suite.scala:1096)
	at pl.touk.nussknacker.engine.management.periodic.UtilsSpec.org$scalatest$wordspec$AnyWordSpecLike$$super$run(UtilsSpec.scala:10)
	at org.scalatest.wordspec.AnyWordSpecLike.$anonfun$run$1(AnyWordSpecLike.scala:1354)
	at org.scalatest.SuperEngine.runImpl(Engine.scala:535)
	at org.scalatest.wordspec.AnyWordSpecLike.run(AnyWordSpecLike.scala:1354)
	at org.scalatest.wordspec.AnyWordSpecLike.run$(AnyWordSpecLike.scala:1352)
	at pl.touk.nussknacker.engine.management.periodic.UtilsSpec.org$scalatest$BeforeAndAfterAll$$super$run(UtilsSpec.scala:10)
	at org.scalatest.BeforeAndAfterAll.liftedTree1$1(BeforeAndAfterAll.scala:213)
	at org.scalatest.BeforeAndAfterAll.run(BeforeAndAfterAll.scala:210)
	at org.scalatest.BeforeAndAfterAll.run$(BeforeAndAfterAll.scala:208)
	at pl.touk.nussknacker.engine.management.periodic.UtilsSpec.run(UtilsSpec.scala:10)
	at org.scalatest.tools.Framework.org$scalatest$tools$Framework$$runSuite(Framework.scala:321)
	at org.scalatest.tools.Framework$ScalaTestTask.execute(Framework.scala:517)
	at sbt.TestRunner.runTest$1(TestFramework.scala:153)
	at sbt.TestRunner.run(TestFramework.scala:168)
	at sbt.TestFramework$$anon$3$$anonfun$$lessinit$greater$1.$anonfun$apply$1(TestFramework.scala:336)
	at sbt.TestFramework$.sbt$TestFramework$$withContextLoader(TestFramework.scala:296)
	at sbt.TestFramework$$anon$3$$anonfun$$lessinit$greater$1.apply(TestFramework.scala:336)
	at sbt.TestFramework$$anon$3$$anonfun$$lessinit$greater$1.apply(TestFramework.scala:336)
	at sbt.TestFunction.apply(TestFramework.scala:348)
	at sbt.Tests$.processRunnable$1(Tests.scala:475)
	at sbt.Tests$.$anonfun$makeSerial$1(Tests.scala:481)
	at sbt.std.Transform$$anon$3.$anonfun$apply$2(Transform.scala:47)
	at sbt.std.Transform$$anon$4.work(Transform.scala:69)
	at sbt.Execute.$anonfun$submit$2(Execute.scala:283)
	at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
	at sbt.Execute.work(Execute.scala:292)
	at sbt.Execute.$anonfun$submit$1(Execute.scala:283)
	at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
	at sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
}

"ignore exceptions inside runSafely block" in {
Utils.runSafely {
throw new RuntimeException("dummy")
Expand Down

0 comments on commit 6789f73

Please sign in to comment.