作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 akka-http 路由规范,其中包含两个测试。我可以单独运行这些中的每一个就好了——但是当我运行整个规范(包括两个测试)时,第二个失败了
Request was neither completed nor rejected within 30 seconds
谁知道这是为什么?
我不知道它是否相关,但无论我单独运行还是一起运行,每个测试似乎都会记录事件两次。 (有时重复的事件在不同的调度程序中,有时它们在同一个调度程序中。)我两次在日志消息上设置断点,所以我假设事件确实被调用了两次。同样,不确定它是否相关,但也许是一条线索。
我也在模拟依赖关系,但我认为这不是问题所在。
我测试的简化版本:
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)
}
}
}
}
}
在此先感谢您的帮助。
最佳答案
您的连接池可能存在问题,导致连接出现超时问题。
尝试显式传递超时,看看是否可行隐式 def 默认值(隐式系统:ActorSystem)= RouteTestTimeout(50.second)
关于ScalatestRouteTest 测试一起运行时超时但单独运行时正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44336281/
我有一个 akka-http 路由规范,其中包含两个测试。我可以单独运行这些中的每一个就好了——但是当我运行整个规范(包括两个测试)时,第二个失败了 Request was neither compl
我想用 ScalatestRouteTest 测试路由,如下所示: trait MyRoutes extends Directives { self: Api with ExecutionCont
我是一名优秀的程序员,十分优秀!