0

I should have missed something. But I am trying to test that my projection is sending a message to another Actor.

My test is really simple and has one assertion:

projectionTestKit.run(projection) {
  val message = mailer.expectMessageType[SendEmailMessage]
  println(s"Got $message")
}

When I run this test, I can see a line printed with the message. However the test is failing :

Future timed out after [3 seconds]
java.util.concurrent.TimeoutException: Future timed out after [3 seconds]
  at scala.concurrent.impl.Promise$DefaultPromise.tryAwait0(Promise.scala:212)
  at scala.concurrent.impl.Promise$DefaultPromise.result(Promise.scala:225)
  at scala.concurrent.Await$.$anonfun$result$1(package.scala:201)
  at scala.concurrent.BlockContext$DefaultBlockContext$.blockOn(BlockContext.scala:62)
  at scala.concurrent.Await$.result(package.scala:124)
  at akka.projection.testkit.scaladsl.ProjectionTestKit.runInternal(ProjectionTestKit.scala:103)
  at akka.projection.testkit.scaladsl.ProjectionTestKit.run(ProjectionTestKit.scala:48)
  at acme.org.MyEventHanlderSpec.$anonfun$new$2(MyEventHanlderSpec.scala:61) <- this is the line with 'mailer.expectMessageType'

As said above, I may have missed something. But at this time I do not understand while my test is failing. The doc state:

While the projection is running, the assert function will be called until it completes without errors (no exceptions or assertion errors are thrown).

And I do not throw any exceptions. So, can someone explain how to test the interaction between a projection and one actor ?

Thanks

Edit; Add whole test code

  val mailer = testKit.createTestProbe[SendEmailMessage]()
  def wrap(
    event: MessageReceived,
    seqNr: Long,
    timestamp: Long = 0L
  ): EventEnvelope[MessageReceived] = {
    EventEnvelope(Offset.sequence(seqNr), "Messages", seqNr, event, timestamp)
  }

  // ..

  val subject = new MyEventHandler(mailer.ref)(system.executionContext, system)
  val Right(email) = EmailAddress.parse("user@example.org")

  val events = Source(
    Seq(
      wrap(MessageReceived(Instant.now(), email), 1)
    )
  )
  val source = TestSourceProvider[Offset, EventEnvelope[MessageReceived]](
    events,
    extractOffset = env => env.offset
  )
  val projection = TestProjection[Offset, EventEnvelope[MessageReceived]](
    ProjectionId("TestProjection", "Fake"),
    source,
    () => subject
  )

  projectionTestKit.run(projection) {
    val message = mailer.expectMessageType[SendEmailMessage]
    println(s"Got $message")
  }
gervais.b
  • 2,294
  • 2
  • 22
  • 46

0 Answers0