Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestServer.isRunning throws an exception when the server is not running. #12331

Closed
tanin47 opened this issue Jan 19, 2024 · 3 comments · Fixed by #12409
Closed

TestServer.isRunning throws an exception when the server is not running. #12331

tanin47 opened this issue Jan 19, 2024 · 3 comments · Fixed by #12409
Milestone

Comments

@tanin47
Copy link
Sponsor Contributor

tanin47 commented Jan 19, 2024

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

throw new IllegalStateException("Test server not running")

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.

@mkurz
Copy link
Member

mkurz commented Jan 22, 2024

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?

@tanin47
Copy link
Sponsor Contributor Author

tanin47 commented Jan 23, 2024

Sounds good. I can do that this weekend. Would love to help contribute.

@tanin47
Copy link
Sponsor Contributor Author

tanin47 commented Feb 3, 2024

When I said "this weekend", I mean "a weekend" 🤣 . Here's the PR: #12352

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants