-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Improve getTestServerIfRunning #12352
Conversation
@@ -71,17 +65,23 @@ case class TestServer(config: ServerConfig, application: Application, serverProv | |||
/** | |||
* The address that the server is running on. | |||
*/ | |||
def runningAddress: String = getTestServerIfRunning.mainAddress.getAddress.getHostAddress | |||
def runningAddress: String = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same behavior of raising an exception is kept.
|
||
/** | ||
* The HTTP port that the server is running on. | ||
*/ | ||
def runningHttpPort: Option[Int] = getTestServerIfRunning.httpPort | ||
def runningHttpPort: Option[Int] = getTestServer.map(_.httpPort) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return None instead of raising an exception for both functions. The return types are the same.
|
||
/** | ||
* The HTTPS port that the server is running on. | ||
*/ | ||
def runningHttpsPort: Option[Int] = getTestServerIfRunning.httpsPort | ||
def runningHttpsPort: Option[Int] = getTestServer.map(_.httpsPort) | ||
|
||
/** | ||
* True if the server is running either on HTTP or HTTPS port. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function wouldn't raise an exception anymore. it would just return false.
I know the approach taken was my idea in #12331 (comment), however looking at the pull request now, I would say the changes in behaviour are too much. Of course, the thing that still needs fixing is to make @tanin47 Thanks for taking the time, specially for reporting the problem. I will go with #12409 because IMHO that is all that needs to be done right now. Thanks again! |
No worries. Thank you for improving it. |
Pull Request Checklist
Helpful things
Fixes
Fixes #12331
Purpose
Improve the interface of TestServer. Currently, if a TestServer doesn't exist, a few functions raise an exception.
Those functions should have return
None
(e.g.def runningHttpPort: Option[Int]
) orfalse
(e.g.def isRunning: Boolean
) instead of raising an exception.