Timer test in Scala is giving a confusing error

When trying to test an action that is creating a timer in Scala a confusing error is received:

Incompatible ActionContext instance. Found class kalix.scalasdk.testkit.impl.TestKitActionContext, expecting kalix.javasdk.impl.action.ActionContextImpl

Reproducting this is easy:

In test:

"handle command ProcessIdChanged" in {
   val service = IdPoliciesActionImplTestKit(new IdPoliciesActionImpl(_))
   val result  = service.processIdChanged(IdState(id = "123456"))

In “actual code”:

  override def processIdChanged(idState: IdState): Action.Effect[Empty] = {
    val timerRegistration = timers
        name = s"expire-id-timer-${idState.Id}",
        delay = 30.minutes,
        deferredCall = components.Id
          .expire(ExpireIdCommand(id = idState.businessId))
      .map(_ => Empty.defaultInstance)

1 Like

Hi @roikonen,

currently testing timers with a *TestKit is not supported. The idea behind *TestKits is to allow a unit-like testing of a single Kalix component. You can still test timers but with integration tests, e.g. testing the actual outcome of timer call.