【问题标题】:Modifying ask timeout in akka testkit修改akka testkit中的询问超时
【发布时间】:2017-08-11 06:41:59
【问题描述】:

我尝试了六种不同的方法,但我似乎无法修改演员询问的默认超时值。这意味着它几乎总是在 CI 服务器上失败。

这是我当前的迭代。有几个尝试捆绑在一起。他们都没有做任何事情来修改从 1 秒开始的超时值。

基础测试类

import akka.actor.ActorSystem
import akka.testkit.TestKit
import com.typesafe.config.ConfigFactory
import org.specs2.mutable.SpecificationLike
import org.specs2.specification.AfterEach
import org.specs2.specification.core.Fragments

abstract class TestActors
    extends TestKit(ActorSystem("testsystem", ConfigFactory.load("test-application.conf")))
    with SpecificationLike
    with AfterEach {
  override def map(fs: => Fragments) = super.map(fs) ^ step(system.terminate, global = true)
  def after = system.terminate()
}

规格

class RepoSpec(implicit ee: ExecutionEnv) extends TestActors {
  isolated

  implicit val timeout = Timeout(5 seconds)

  val repo = system.actorOf(Props(classOf[Repo], data))

  "return None when there's no such record" >> {
    implicit val timeout = Timeout(30 seconds)
    val record = repo ? GetRecord(1, RecordKey(1, 1, 1))
    record must beEqualTo(Option.empty[Record]).await
  }
}

src/test/resources/test-application.conf

akka.test {
  timefactor=10
  single-expect-default=5000
}

规格在我的笔记本电脑上完成,但在 Travis 上失败:

[error] x return None when there's no such record
[error]  Timeout after 1 second (retries = 0, timeout = 1 second), timeFactor = 1 (TestActors.scala:10)

编辑:奇怪的是错误消息中引用的行是TestActors.scala:10 - 这是基本测试类的类定义。

如果我能让系统理解 1 秒太快,我会非常高兴。

【问题讨论】:

    标签: scala akka specs2 akka-testkit


    【解决方案1】:

    您可以将timeout 设置覆盖为大于一秒:

    record must beEqualTo(Option.empty[Record]).await(timeout = 5.seconds)
    

    但是,recommended 的做法是在 CI 服务器上运行测试时在 specs2 中设置更高的 timeFactor 执行环境参数。等待超时设置乘以timeFactor,其默认值为one。在您的测试中,timeout 的值为一秒,timeFactor 为一,导致总超时为一秒:1 second * 1。根据您的 CI 服务器更改 timeFactor

    【讨论】:

    • 我没想过要尝试规范 timeFactor,因为超时来自 Akka,而不是 Matcher。但是,它奏效了。我不确定为什么。
    猜你喜欢
    • 2019-12-19
    • 2022-01-05
    • 1970-01-01
    • 2019-12-10
    • 1970-01-01
    • 1970-01-01
    • 2014-04-18
    • 2021-08-25
    • 1970-01-01
    相关资源
    最近更新 更多