Typesafe Slick (v 1.0.1) を使用する Play (v 2.2.0) アプリを持っています。PostgreSQL データベースをシードし、さまざまなコントローラー アクションを呼び出すテスト (specs2) を作成しようとしています。データの存在を検証します。私のテストでは、次のものがあります。
"Countries" should {
"initialize" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
AppDB.database.withSession {
implicit session: Session =>
AppDB.dal.create
AppDB.dal.seedForTests
AppDB.dal.Countries.findAll().size must be_>=(1)
}
}
}
それだけで、これは正常に機能します。しかし、別のテスト アクションを追加すると、次のようになります。
"respond to Index()" in {
val result = controllers.Countries.index()(FakeRequest())
status(result) must equalTo(OK)
}
私のテストは次のメッセージで失敗します:
SQLException: Attempting to obtain a connection from a pool that has already been shutdown.
スタックトレースの関連部分は次のとおりです。
[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)
...
FakeApplication(...)
とAppDB.database.withSession
ブロックの両方をコードの上位に移動し、val result = controllers.Countries.index(...)
コードをラッパーでラップしようとしましAppDB.database.withSession
たが、まだ運がありませんでした。
方向性をありがとう。