`TestServer.isRunning` throws an exception when the server is not running.
Play Version
Latest
API
Scala
Operating System
N/A
JDK
N/A
Library Dependencies
Expected Behavior
I'd expect it to return true or false
Actual Behavior
It raises an exception when the server is not running.
Reproducible Test Case
https://github.com/playframework/playframework/blob/a77da07e0b2d594af5d538c38803ba2466e20517/testkit/play-test/src/main/scala/play/api/test/TestServer.scala#L28
Here's the code:
case class TestServer(config: ServerConfig, application: Application, serverProvider: Option[ServerProvider]) {
...
private def getTestServerIfRunning: Server = {
val s = server
if (s == null) {
throw new IllegalStateException("Test server not running")
}
s
}
...
def runningHttpPort: Option[Int] = getTestServerIfRunning.httpPort
@ApiMayChange
def isRunning: Boolean = runningHttpPort.nonEmpty || runningHttpsPort.nonEmpty
}
I wonder if we should catch an exception in isRunning.
Best is probably if getTestServerIfRunning would return an Option[Server] instead of thrown an exception...
Ahh.. I see it's private so we could change that right now.
What do you think? you want to provide pull request?
Sounds good. I can do that this weekend. Would love to help contribute.
When I said "this weekend", I mean "a weekend" 🤣 . Here's the PR: https://github.com/playframework/playframework/pull/12352