首页 文章

修改akka testkit中的ask timeout

提问于
浏览
0

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

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

base test class

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()
}

Spec

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秒太快,我会非常高兴 .

1 回答

  • 0

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

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

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

相关问题