.expectNext() uses a regular TestKit TestProbe behind the stage, and this 
has got a default timeout of three seconds. I'm guessing your http call 
takes longer than that and that is why you get an error, in the non 
stream-testkit-example you wait infinitely long for a result to appear.

I can't find an .expectNext that will allow you to specify the timeout as a 
parameter in the current testkit for streams though, what you could do is 
to set it globally for the actor system you are running the test on.

Something like this:

implicit val system = ActorSystem(
  "test",
  ConfigFactory.parseString("akka.test.single-expect-default=300 seconds")
    .withFallback(ConfigFactory.load())
)



Hope this helps!
--
Johan Andrén
Typesafe -  Reactive apps on the JVM
Twitter: @apnylle

On Saturday, August 22, 2015 at 12:08:06 PM UTC+2, Benjamin Lüdicke wrote:
>
> Hi,
> I try to write my first Akka Stream project which periodically fetch data 
> from a remote server via Akka Http and the superpool.
> Now, if I run my test with the akka stream testkit I get back a 
> java.lang.AssertionError. 
> See below. But if I run the test with built in sources and sinks all 
> works fine.
>
> Please help me to understand this behaviour.
>
>
>
> implicit val system = ActorSystem()
>
> implicit val materializer = ActorMaterializer()
>
> implicit val executionContext = system.dispatcher
>
>
> //This code fails with an AssertionError
>
> "Grabber" >> {
>
>   "load data from remote server" >> {
>
>     val sourceUnderTest: Source[(Try[HttpResponse], Int), Unit] = new 
> Grabber().source //system and materializer wil be passed as implicits
>
>     val sub = sourceUnderTest
>
>       .runWith(TestSink.probe[(Try[HttpResponse], Int)])
>
>       .request(n = 1)
>
>       .expectNext()
>
>     sub._1 must beSuccessfulTry.which(_.status === StatusCodes.OK)
>
>   }
>
> }
>
> //This Code works fine
>
> "Grabber" >> {
>
>   "load data from remote server" >> {
>
>     val sourceUnderTest: Source[(Try[HttpResponse], Int), Unit] = new 
> Grabber().source
>
>     val sink = Flow[(Try[HttpResponse],Int)].toMat(Sink.head)(Keep.right)
>
>     val res = for {
>
>       response <- sourceUnderTest.runWith(sink)
>
>     } yield  response._1 must beSuccessfulTry.which(_.status === 
> StatusCodes.OK)
>
>     Await.result(res, Duration.Inf)
>
>   }
>
> }
>
>
>
>
>
>
>
> java.lang.AssertionError: assertion failed: timeout (3 seconds) during 
> expectMsgClass waiting for class akka.stream.testkit.StreamTestKit$OnNext
>     at scala.Predef$.assert(Predef.scala:165)
>     at akka.testkit.TestKitBase$class.expectMsgClass_internal(TestKit.
> scala:423)
>     at akka.testkit.TestKitBase$class.expectMsgType(TestKit.scala:396)
>     at akka.testkit.TestKit.expectMsgType(TestKit.scala:718)
>     at akka.stream.testkit.TestSubscriber$ManualProbe.expectNext(
> StreamTestKit.scala:223)
>     at RemoteSpec$$anonfun$1$$anonfun$apply$1.apply(RemoteSpec.scala:41)
>     at RemoteSpec$$anonfun$1$$anonfun$apply$1.apply(RemoteSpec.scala:36)
>     at org.specs2.matcher.MatchResult$$anon$12$$anonfun$asResult$1.apply(
> MatchResult.scala:310)
>     at org.specs2.matcher.MatchResult$$anon$12$$anonfun$asResult$1.apply(
> MatchResult.scala:310)
>     at org.specs2.execute.ResultExecution$class.execute(ResultExecution.
> scala:25)
>     at org.specs2.execute.ResultExecution$.execute(ResultExecution.scala:
> 120)
>     at org.specs2.execute.Result$$anon$10.asResult(Result.scala:227)
>     at org.specs2.execute.AsResult$.apply(AsResult.scala:25)
>     at org.specs2.matcher.MatchResult$$anon$12.asResult(MatchResult.scala:
> 310)
>     at org.specs2.execute.AsResult$.apply(AsResult.scala:25)
>     at org.specs2.main.CommandLineAsResult$$anon$1.asResult(
> CommandLineAsResult.scala:17)
>     at org.specs2.main.CommandLineAsResult$$anonfun$apply$1.apply(
> CommandLineAsResult.scala:21)
>     at org.specs2.main.CommandLineAsResult$$anonfun$apply$1.apply(
> CommandLineAsResult.scala:21)
>     at org.specs2.specification.dsl.mutable.
> ExampleDsl1$BlockExample$$anonfun$$greater$greater$1.apply(ExampleDsl.
> scala:39)
>     at org.specs2.specification.dsl.mutable.
> ExampleDsl1$BlockExample$$anonfun$$greater$greater$1.apply(ExampleDsl.
> scala:39)
>     at org.specs2.specification.core.Execution$$anonfun$withEnv$1$
> ...

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to