I have a spec for my akka-http route with two tests in it. I can run each of these individually just fine -- but when I run the whole spec (including both tests), the 2nd one fails with
Request was neither completed nor rejected within 30 seconds
Does anyone know why this is?
I don't know if it's relevant, but each test seems to be logging events twice whether I run them alone or together. (Sometimes the duplicated events are in different dispatchers and sometimes they are in the same one.) I am hitting breakpoints on the log messages twice so I assume the events are really being called twice. Again, not sure if it's relevant, but maybe a clue.
I'm also mocking out dependencies, but I don't think that's the issue.
Dumbed down version of my test:
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)
}
}
}
}
}
Thanks in advance for any help.
Aucun commentaire:
Enregistrer un commentaire