-
Notifications
You must be signed in to change notification settings - Fork 923
Makes CoreNLPClient not checks ensure_alive when start_server=StartSe… #1061
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
Makes CoreNLPClient not checks ensure_alive when start_server=StartSe… #1061
Conversation
…rver.DONT_START Makes CoreNLPClient not checking if the server is alive when start_server=StartServer.DONT_START
raise TimeoutException(r.text) | ||
else: | ||
raise AnnotationException(r.text) | ||
except requests.exceptions.Timeout as e: |
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.
good catch!
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.
Thanks
I also take off the:
if r.text == "CoreNLP request timed out. Your document may be too long.":
(from below) because it has probably not sense to check r.text after a HTTP exception (probably it will not have anything)
stanza/tests/server/test_client.py
Outdated
""".strip() | ||
|
||
class HTTPMockServerTimeoutContext: | ||
""" For lunching an HTTP server on certain port with an specified delay at responses """ |
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.
^launching
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.
Sorry! The spellchecker didn't notice (maybe) because lunching exists. Funny
I corrected with a second commit
|
||
class HTTPMockServerTimeoutContext: | ||
""" For lunching an HTTP server on certain port with an specified delay at responses """ | ||
def __init__(self, port, timeout_secs): |
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.
i kind of want this to find an open port... but at the same time i recognize there are a lot of tests which already use 9001 in exactly the same manner
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.
Is it ok if we leave this class as it is (with the parametrized port) and delegate the responsibility of setting the port to the caller?
[Text=. CharacterOffsetBegin=66 CharacterOffsetEnd=67 PartOfSpeech=.] | ||
""".strip() | ||
|
||
class HTTPMockServerTimeoutContext: |
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.
I like this idea a lot. Thanks!
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.
Thanks, many people also use flask
or pytest-httpserver
for mocking HTTP servers. Later could be a better option but I think this doesn't introduce any extra dependency (as http.server is installed by default)
one minor change requested, plus if you can think of a way around assuming 9001 is always open, that would be great. thanks! |
When you bind a socket and give 0 as a port number, the OS will bind it to the first available unused port.
(The binding process occurs at HTTPServer constructor called so it's an easy refactor)
Credits: SO Notice that nothing the port remains free (it could happen a running condition, for example if tests are executed in parallalle and interfere each other). I suggest the number (2) solution.
Credits: SO I tested and on test_client.py and this solution works also for Notice that the java Tell me what you prefer. But I think it's better to only modify HTTPMockServerTimeoutContext on this PR. Then I can create other PR for fixing the other test cases if you need. |
Since half the test uses 9001 anyway, it's not necessary to change any part of it to scan for open ports. It would be a nice TODO for later, though. I'll take another look when I get home and merge it |
Thanks! |
Description
Makes CoreNLPClient not check if the server is alive when start_server=StartServer.DONT_START
Fixes Issues
#1059
Unit test coverage
test_external_server renamed to test_external_server_available (and modified)
test_external_server_timeout added
test_external_server_unavailable added
pytest executed successfully on stanza/tests/server/test_client.py
Known breaking changes/behaviors
Now when start_server=StartServer.DONT_START the clients must be sure the server is running. Otherwise (if they launched a server instance but didn't wait for enough) they could get a connection error.