[play-2.1-RC2-java] Increase FakeRequest Timeout

923 views
Skip to first unread message

The YelllowDart

unread,
Jan 15, 2013, 6:42:14 PM1/15/13
to play-fr...@googlegroups.com
How do you increase the length of FakeRequest's timeout (I believe it's set to 10 seconds currently)? I like would to debug a unit and sit on breakpoint in AccountController for longer than 10 seconds:

public void login_emptyLoginModel_badRequestAndSessionTokenNotSet() {

    FakeRequest loginRequest = fakeRequest();

   Result result = callAction(routes.ref.AccountController.login(), loginRequest);

   assertThat(status(result)).isEqualTo(Status.BAD_REQUEST);

   assertThatSessionTokenIsNotSet(result);

 }


If the request takes longer than 10 seconds I get this exception:
java.util.concurrent.TimeoutException: Futures timed out after [10000 milliseconds]
at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:96)
at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:58)
at scala.concurrent.Await$$anonfun$ready$1.apply(package.scala:86)
at scala.concurrent.Await$$anonfun$ready$1.apply(package.scala:86)
at scala.concurrent.BlockContext$DefaultBlockContext$.blockOn(BlockContext.scala:53)
at scala.concurrent.Await$.ready(package.scala:86)
at play.api.libs.concurrent.PlayPromise.await(Promise.scala:134)
at play.api.libs.concurrent.PlayPromise.await(Promise.scala:126)
at play.core.j.JavaResultExtractor$.getStatus(JavaResults.scala:35)
at play.core.j.JavaResultExtractor.getStatus(JavaResults.scala)
at play.test.Helpers.status(Helpers.java:154)
at gov.nationalchildrensstudy.cuttle.gui.controllers.AccountControllerTest.login_emptyLoginModel_badRequestAndSessionTokenNotSet(AccountControllerTest.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


scott clasen

unread,
Jan 15, 2013, 6:45:38 PM1/15/13
to play-fr...@googlegroups.com
+10 I think it would be pretty cool if play was in dev or test mode and it detected that debug was turned on by 

boolean isDebug = java.lang.management.ManagementFactory.getRuntimeMXBean(). getInputArguments().toString().contains("-agentlib:jdwp");

Or something similar, the timeout would get set to 10 minutes or something sufficiently huge. 

Przemysław Pokrywka

unread,
Apr 17, 2013, 5:55:48 PM4/17/13
to play-fr...@googlegroups.com
+1

For now I'm working that around by just calling Thread.sleep before status (which uses the short timeout). That's obviously lame and I'd love to have a clean way of doing that. I'm using Play 2.1.0 too.

Przemek

Prashant Kumar

unread,
Jul 26, 2013, 12:29:26 AM7/26/13
to play-fr...@googlegroups.com

Dear Przemek,
                        Did u find any solution for this issue. How can we increase the future timeout?

Pokrywka, Przemysław

unread,
Jul 26, 2013, 5:50:17 AM7/26/13
to play-fr...@googlegroups.com
No Prashant, I did not, sorry. I've just applied the mentioned workaround.
Message has been deleted

user123

unread,
Oct 11, 2013, 1:31:10 PM10/11/13
to play-fr...@googlegroups.com, przemysla...@blstream.com
This is strange, I'm trying the workaround, and no matter which value I put in sleep, I still get the timeout:

  "test" in {
    running(FakeApplication()) {
      val Some(result) = route(FakeRequest(GET, "/api/foo?par=val"))
      Thread.sleep(50000)
      status(result) must equalTo(OK)
    }

The request is actually very quick so I suppose something else is wrong, but what could it be?

user123

unread,
Oct 11, 2013, 1:46:19 PM10/11/13
to play-fr...@googlegroups.com, przemysla...@blstream.com
I found the reason but I don't understand it, if I run the test alone it works (without Thread.sleep). If I run another test alone, it works(without Thread.sleep) but if I run both tests together I get timeout (even with Thread.sleep). What could it be?

  "test1" in {
    running(FakeApplication()) {

      val result = controllers.MyController.index()(FakeRequest())
      Thread.sleep(20000)
      status(result) must equalTo(OK)
      contentType(result) must beSome("text/html")
      charset(result) must beSome("utf-8")

    }
  }

  "test2" in {
    running(FakeApplication()) {
      val Some(result) = route(FakeRequest(GET, "/api/foo?par=val"))
      Thread.sleep(20000)
      status(result) must equalTo(OK)

tim wilkins

unread,
Mar 28, 2014, 6:38:46 AM3/28/14
to play-fr...@googlegroups.com, przemysla...@blstream.com
The problem is due to you using the Play Actor system which is tied to to the play application. You are creating and shutting down a FakeApplication instance for each test which has to start and stop the Actor system.

Try adding:
play.api.Play.start(FakeApplication())

at the top of your test class and remove all the "running(FakeApplication()) {}" blocks around each test. This will ensure that you only start one FakeApplication for all the tests in your test class.

ssch...@jibe.com

unread,
Mar 28, 2014, 2:14:21 PM3/28/14
to play-fr...@googlegroups.com
In 2.3 you will be able to set a different timeout:
https://github.com/playframework/playframework/pull/2414

In the meantime I hijacked just the Helpers class and set the timeout to 30 seconds.

s.

Nir

unread,
Jan 24, 2018, 4:51:41 PM1/24/18
to Play Framework
Is there any fix to this in play 2.6? I am getting Request timeout after 20 seconds.

        val fakeRequest = FakeRequest(POST, "/api/v1/data/json") 
                            .withJsonBody(jsonReq)
        val Some(result) = route(app, fakeRequest)
        
        status(result) mustEqual OK

Greg Methvin

unread,
Jan 24, 2018, 9:14:42 PM1/24/18
to play-framework

You just need to declare or override that timeout, or explicitly pass some other timeout like status(result)(1.minute)

What's New with Xactly

        

--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/a60e4046-fc2a-433d-b5ab-d6f27692998c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Greg Methvin
Tech Lead - Play Framework

Nir

unread,
Jan 24, 2018, 10:23:45 PM1/24/18
to Play Framework
Got it. Thanks
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages