我在运行多个功能规范(使用 specs2)时遇到问题,特别是启动 TestServer、打开 HTMLUNIT 浏览器并导航到页面以检查元素的测试。有问题的页面加载了我们在 ajax 请求上测试的元素。等待元素出现超时,并显示以下错误消息。
代码片段:
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()
...
}
}
我们得到错误:
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)
虽然测试在单独运行时有效,但在同时运行两个或多个测试时会出现错误。
尽管我的示例是 Scala Play 应用程序,但似乎与此问题有关。谁能确认此问题已在较新版本的 Play 中得到解决?或者,是否有解决方法来避免 Play 2.0.1 中出现此错误。