我已经尝试了六种不同的方法,但我似乎无法修改演员询问的默认超时值。这意味着它几乎总是在 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 秒太快,我会很高兴。