Specs2 test timeout error when running more than 1 test

175 views
Skip to first unread message

user123

unread,
Oct 11, 2013, 2:37:26 PM10/11/13
to play-fr...@googlegroups.com
Play version: 2.1

I test 2 methods of my controller separatedly - test runs without problems. I run them together and get a timeout in the second of them:

[error]   TimeoutException: Futures timed out after [10000 milliseconds] (Promise.scala:134)

These methods don't have any dependency between them. I also got same error with other 2 methods. 

Here are my current 2 tests:

  "a" in {
    running(FakeApplication()) {
      val Some(result) = route(FakeRequest(GET, "/api/a"))
      status(result) must equalTo(OK)
      contentType(result) must beSome("application/json")
      charset(result) must beSome("utf-8")

    }
  }

    "b" in {
      running(FakeApplication()) {
        val Some(result) = route(FakeRequest(GET, "/api/b"))
        status(result) must equalTo(OK)
        contentType(result) must beSome("application/json")
        charset(result) must beSome("utf-8")


      }
  }

What's going on? Maybe FakeApplication of the first test doesn't close properly? I don't see any error in log besides the timeout. I also tried putting a Thread.sleep call after the call (before status-test) in the second test, but this didn't help, not even with 60 seconds.

David Weinberg

unread,
Oct 11, 2013, 5:03:14 PM10/11/13
to play-fr...@googlegroups.com
I believe it runs them simultaneously and probably against the same database.  You may be getting some sort of deadlock going on.  Here's what I do:
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
Each test gets its own database this way.

user123

unread,
Oct 12, 2013, 5:28:21 PM10/12/13
to play-fr...@googlegroups.com
But in my controller the methods also could be called by different clients at the same time, and the app is of course using the same database. Why should it be different for test?

Anyways I tried it, I'm using MongoDB, inMemoryDatabase doesn't seem to work with it. I get many strange errors.

奥村康樹

unread,
Oct 13, 2013, 4:25:12 AM10/13/13
to play-fr...@googlegroups.com
I got same problem before and how I fixed it is to add `sequential` in your spec like the following:

class YourSpec extends Specification with BeforeExample {
  sequential

  // This is for isolation test. So not necessary
  def before = {
    // clean your database
  }

and add the below in your Build.scala explicitly:
`parallelExecution
in Test := false`
(I said `explicitly` because default play parallel Excecution setting is false. )








2013/10/13 user123 <ivans...@gmail.com>

--
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-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

David Weinberg

unread,
Oct 13, 2013, 6:11:58 PM10/13/13
to play-fr...@googlegroups.com
I don't know how MongoDB works, but in an RDBMS, it's not the DML that's causing the problem, but the concurrent DDL that might be on the same tables.  As 奥村 says, you can try to make it sequential, or you can do something so that it creates a different MongoDB instance for each test.
Reply all
Reply to author
Forward
0 new messages