2017-06-02 99 views
1

我有一个对其中有两个测试的akka​​-http路由的规范。我可以单独就好运行其中的每个 - 但是当我运行完整的型号规格(包括测试),第二届一个失败ScalatestRouteTest在一起运行时测试超时,但单独运行良好

请求既不完成也30秒

内拒绝有人知道为什么吗?

我不知道它是否相关,但每次测试似乎都是记录事件两次,无论是单独运行还是一起运行。 (有时重复的事件在不同的调度器中,有时它们在同一个事件中。)我在日志消息上敲击两次断点,所以我假设事件真的被调用两次。再次,不确定它是否相关,但可能是线索。

我也嘲笑依赖,但我不认为这是问题。

简单化版本我测试的:

package com.mystuff 

import akka.actor.ActorSystem 
import com.mystuff._ 
import org.mockito.Mockito._ 
import akka.http.scaladsl.model.StatusCodes.{NotFound, OK} 
import akka.http.scaladsl.server.Directives 
import akka.http.scaladsl.testkit.{RouteTestTimeout, ScalatestRouteTest} 
import org.scalatest.{BeforeAndAfterEach, FunSpec, Matchers} 

import scala.concurrent.Future 
import scala.concurrent.duration._ 

/** 
    * Created by bathalh on 6/2/17. 
    */ 
class OAuthClentServiceASpec extends FunSpec with Matchers with BeforeAndAfterEach with Directives with ScalatestRouteTest 
{ 
    implicit def default(implicit system: ActorSystem) = RouteTestTimeout(30 seconds) 

    private var mockDependencyFun: DependencyFun = _ 
    private var testObject: MyService = _ 

    override def beforeEach = 
    { 
     mockDependencyFun = mock(classOf[DependencyFun]) 
     when(mockDependencyFun(anyString())).thenReturn(Future successful "OK") 

     testObject = new MyService() { 
      def getDepFunction = mockDependencyFun 
     } 

    } 

    describe("OAuthClentService Application") 
    { 
     import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ 
     import com.mystuff.MyJsonProtocol._ 

     describe("Get a specific client") 
     { 
      it("Returns 404 with useful message when client does not exist") 
      { 
       val clientId = "does not exist client" 
       Get(s"/clients/$clientId") ~> testObject.routes ~> check { 
        status should be (NotFound) 
        responseAs[ErrorResponse] should be (ErrorResponse(Set(s"Client not found: $clientId"))) 
       } 
      } 

      it("Returns client information when client exists") 
      { 
       val clientId = "ValidClient" 
       Get(s"/clients/$clientId") ~> testObject.routes ~> check { 
        status should be (OK) 
        val clientInfo = responseAs[ClientResponse] 
        clientInfo.id should be (clientId) 
       } 
      } 
     } 
    } 
} 

预先感谢任何帮助。

回答

0

可能存在连接池问题,由于连接池出现超时问题。

尝试明确地传递超时,看看它的作品了 implicit def default(implicit system: ActorSystem) = RouteTestTimeout(50.second)

+0

我将它设置为30秒,这应该是足够的。但是你可能对连接池是正确的;我会乱搞我的'application.conf'设置,看看我能否弄清楚发生了什么。谢谢! –

相关问题