2017-08-11 25 views
0

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

这是我目前的迭代。有几个捆绑在一起的尝试。他们都没有做任何修改超时值从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 /测试/资源/测试application.conf

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

在规格上我的笔记本电脑完成,但特拉维斯失败:

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

回答

0

您可以覆盖timeout设置的东西超过一秒更大:

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

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

+0

我没有想过要试试规格timeFactor,因为超时来自Akka,而不是Matcher。但是,它的工作。我不确定为什么。 – Synesso