Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run multiple functional specs with TestServer in Play 2.0.1?

I am having problems running multiple functional specs (using specs2), specifically tests that start a TestServer, open an HTMLUNIT browser, and navigate to a page to check an element. The page in question loads the elements that we test on an ajax request. The wait for the element to be present times out with the error message below.

Code snippet:

trait CommonSteps extends BaseSpecfication {
  val testServer: TestServer = TestServer(3333)
  val testServerBaseURL: String = "http://localhost:3333/"

  override def map(fs: => Fragments) =
    Step(testServer.start()) ^ super.map(fs) ^ Step(testServer.stop())

}

class FunctionalTest1 extends Specification with CommonSteps { def is =
  ...

  ... extends When[...] {
    val browser: TestBrowser = TestBrowser.of(HTMLUNIT)
    browser.goTo(testServerBaseURL + "/some_path")
    browser
  }

  ... extends Then[...] {
    browser.await.until("element that is loaded on ajax request").isPresent()
    ...
  }

}

We get the error:

Caused by: java.sql.SQLException: Attempting to obtain a connection from a pool that has already been shutdown.
Stack trace of location where pool was shutdown follows:
  java.lang.Thread.getStackTrace(Thread.java:1479)
  com.jolbox.bonecp.BoneCP.captureStackTrace(BoneCP.java:543)
  com.jolbox.bonecp.BoneCP.shutdown(BoneCP.java:159)
  com.jolbox.bonecp.BoneCPDataSource.close(BoneCPDataSource.java:123)
  play.api.db.BoneCPApi.shutdownPool(DB.scala:387)
  play.api.db.BoneCPPlugin$$anonfun$onStop$1.apply(DB.scala:252)
  play.api.db.BoneCPPlugin$$anonfun$onStop$1.apply(DB.scala:250)
  scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
  scala.collection.immutable.List.foreach(List.scala:45)
  play.api.db.BoneCPPlugin.onStop(DB.scala:250)
  play.api.Play$$anonfun$stop$1$$anonfun$apply$1.apply(Play.scala:75)
  play.api.Play$$anonfun$stop$1$$anonfun$apply$1.apply(Play.scala:74)
  scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
  scala.collection.immutable.List.foreach(List.scala:45)
  play.api.Play$$anonfun$stop$1.apply(Play.scala:74)
  play.api.Play$$anonfun$stop$1.apply(Play.scala:74)
  scala.Option.map(Option.scala:133)
  play.api.Play$.stop(Play.scala:73)
  play.core.server.NettyServer.stop(NettyServer.scala:73)

While the test works when run in isolation, we get the error when running two or more of them together.

It seems to be related to this issue, though my example is a Scala Play app. Can anyone confirm that this issue is fixed in a newer version of Play? Or, is there a workaround to avoid this error in Play 2.0.1.

like image 229
Ratan Sebastian Avatar asked Jun 22 '12 14:06

Ratan Sebastian


1 Answers

This issue will be fixed in Play 2.0.2, which is currently in RC state. It is safe to upgrade from 2.0.1 to 2.0.2, as everything is backwards compatible.

Thanks to @guillaume-bort for providing this information.

like image 104
Chris Avatar answered Nov 15 '22 04:11

Chris