title: How to get past SQLException: Attempting to obtain a connection from a pool that has already been shutdown
body: <p>I've got a Play (v 2.2.0) app using Typesafe Slick (v 1.0.1), and I'm trying to write a test (specs2) that seeds a PostgreSQL database, then makes a call to various controller actions to validate the existence of the data. In my test, I have:</p>
  
  <pre><code> "Countries" should {
        "initialize" in {
          running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
            AppDB.database.withSession {
              implicit session: Session =&gt;
  
                AppDB.dal.create
                AppDB.dal.seedForTests
  
                AppDB.dal.Countries.findAll().size must be_&gt;=(1)
            }
          }
        }
  </code></pre>
  
  <p>by itself, this works fine. But, when I add another test action, like:</p>
  
  <pre><code>  "respond to Index()" in {
      val result = controllers.Countries.index()(FakeRequest())
  
      status(result) must equalTo(OK)
    }
  </code></pre>
  
  <p>my test fails with the message: </p>
  
  <pre><code>SQLException: Attempting to obtain a connection from a pool that has already been shutdown.
  </code></pre>
  
  <p>The relevant parts of the stacktrace are:</p>
  
  <pre><code>[error]     SQLException: Attempting to obtain a connection from a pool that has already been shutdown. 
  [error] Stack trace of location where pool was shutdown follows:
  [error]  java.lang.Thread.getStackTrace(Thread.java:1503)
  [error]  com.jolbox.bonecp.BoneCP.captureStackTrace(BoneCP.java:559)
  [error]  com.jolbox.bonecp.BoneCP.shutdown(BoneCP.java:161)
  [error]  com.jolbox.bonecp.BoneCPDataSource.close(BoneCPDataSource.java:143)
  [error]  play.api.db.BoneCPApi.shutdownPool(DB.scala:414)
  [error]  play.api.db.BoneCPPlugin$$anonfun$onStop$1.apply(DB.scala:264)
  [error]  play.api.db.BoneCPPlugin$$anonfun$onStop$1.apply(DB.scala:262)
  [error]  scala.collection.immutable.List.foreach(List.scala:318)
  [error]  play.api.db.BoneCPPlugin.onStop(DB.scala:262)
  ...
  </code></pre>
  
  <p>I've tried moving both the <code>FakeApplication(...)</code> and <code>AppDB.database.withSession</code> blocks higher in the code, as well as wrapping the <code>val result = controllers.Countries.index(...)</code> code in an <code>AppDB.database.withSession</code> wrapper, but still have had no luck. </p>
  
  <p>Thank you for any direction.</p>