Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a tentative answer as I have currently tested on play 2.2.0 and I can't reproduce your bug, using a MYSQL database. </p> <p>I feel there might be a very tricky bug in your code. First of all, if you explore the DBPlugin implementation provided by Play, BoneCPPPlugin:</p> <pre><code> /** * Closes all data sources. */ override def onStop() { dbApi.datasources.foreach { case (ds, _) =&gt; try { dbApi.shutdownPool(ds) } catch { case NonFatal(_) =&gt; } } val drivers = DriverManager.getDrivers() while (drivers.hasMoreElements) { val driver = drivers.nextElement DriverManager.deregisterDriver(driver) } } </code></pre> <p>You see that the onStop() method closes the connection pool. So it's clear, you are providing to the second test example an application which has already been stopped (and therefore its plugins are stopped and the db connectin pool closed).</p> <p>Scalatests and specs2 run the test in parallel, and you can rely on the test helper because it's thread-safe:</p> <pre><code> def running[T](fakeApp: FakeApplication)(block: =&gt; T): T = { synchronized { try { Play.start(fakeApp) block } finally { Play.stop() play.api.libs.ws.WS.resetClient() } } } </code></pre> <p>However, when you do </p> <pre><code>DB.getDataSource("test") </code></pre> <p>From the source code of Play: </p> <pre><code> def getDataSource(name: String = "default")(implicit app: Application): DataSource = app.plugin[DBPlugin].map(_.api.getDataSource(name)).getOrElse(error) </code></pre> <p>So here there is an implicit, does which not get resolved to FakeApplication (it is not an implicit in scope!!!), but to <code>Play.current</code> and it appears that in the second case, this is not what you were expecting it to be, Play.current still point to the previous instance of FakeApplication: it probably depends on how implicit are captured in closures</p> <p>If you however, refactor the fakeApp method, you can ensure the application you just created is used to resolve the implicit (you can always make explicit the value for an implicit parameter)</p> <pre><code> def fakeApp[T](block: =&gt; T): T = { val fakeApplication = FakeApplication(additionalConfiguration = postgresDatabase("test") ++ Map("evolutionplugin" -&gt; "disabled")) running(fakeApplication) { def database = Database.forDataSource(DB.getDataSource("test")(fakeApplication)) database.withSession { implicit s: Session =&gt; block } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload