Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #282 - micbou:shutdown-tests, r=puremourning
[READY] Properly shut down on Windows ### Problem When killing a process on Windows, it is terminated like it received a `SIGKILL` signal on Linux. This means that @atexit functions will not be called. In our case, `ServerCleanup` is not executed: completers `Shutdown` methods are not called, neither the `Shutdown` function in the global extra conf. In particular, subservers like `OmniSharpServer` and `Tern.js` are left running. This issue happens in two situations: - [a client like YCM terminates the ycmd server](https://github.com/Valloric/YouCompleteMe/blob/master/python/ycm/youcompleteme.py#L175); - [watchdog plugin pulls the trigger](https://github.com/Valloric/ycmd/blob/master/ycmd/watchdog_plugin.py#L92). How to solve it? ### Solution First situation should be solved by adding a new handler `/shutdown` to properly shut down the ycmd server from a client. Unfortunately, `waitress` and `bottle` don't provide an easy way to shut it down. Using `sys.exit()` in the `/shutdown` handler will not work because it is run in a thread. The solution is to use the same mechanism as in the watchdog plugin. After cleaning up, we start a thread to immediately kill the server. Second situation is fixed by using the function associated to the `/shutdown` handler in the watchdog plugin. ### Tests To test that the shutdown handler and the watchdog plugin are properly working, we need to start the ycmd server for real. We cannot use [webtest](https://webtest.readthedocs.org/en/latest/) here. I added 4 tests, which are a combination of shutting down ycmd without and with a subserver, from a request and from the watchdog plugin. [psutil](http://pythonhosted.org/psutil/) module was added to the test requirements to work with processes in a portable way. In order to test the watchdog plugin, I added a command-line argument to set the `check_interval_seconds` variable. Since we are starting subprocesses in those tests, some changes were needed to enable coverage in Python subprocesses. Another change to improve coverage was to update Waitress to version 0.8.10. See the commit message for some explanation. A benefit of those tests is a significant increase in coverage (~6%). ### Caveats - Tests may introduce flakyness. Robustness should be improved; - Coverage seems to cause issue with the Gocode daemon. Not sure if it is related to this PR. Need to investigate. ### Next - Update YCM to use the `shutdown` handler (fix issue ycm-core/YouCompleteMe#876); - Fix logfiles clean up on Windows. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/valloric/ycmd/282) <!-- Reviewable:end -->
- Loading branch information
Showing
13 changed files
with
457 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
[report] | ||
omit = | ||
*/third_party/requests/* | ||
*/tests/* | ||
*/__init__.py | ||
|
||
[run] | ||
parallel = True | ||
source = | ||
ycmd | ||
|
||
[paths] | ||
source = | ||
ycmd/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ pip-log.txt | |
|
||
# Unit test / coverage reports | ||
.coverage | ||
.coverage.* | ||
cover/ | ||
.tox | ||
nosetests.xml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule waitress
updated
26 files
+23 −0 | .travis.yml | |
+49 −2 | CHANGES.txt | |
+8 −0 | CONTRIBUTORS.txt | |
+4 −22 | docs/conf.py | |
+36 −16 | docs/index.rst | |
+3 −0 | rtd.txt | |
+4 −4 | setup.py | |
+12 −5 | tox.ini | |
+1 −1 | waitress/__init__.py | |
+3 −8 | waitress/buffers.py | |
+8 −9 | waitress/channel.py | |
+0 −5 | waitress/compat.py | |
+3 −3 | waitress/parser.py | |
+21 −0 | waitress/runner.py | |
+10 −0 | waitress/server.py | |
+28 −26 | waitress/task.py | |
+7 −4 | waitress/tests/fixtureapps/getline.py | |
+10 −11 | waitress/tests/test_buffers.py | |
+4 −4 | waitress/tests/test_channel.py | |
+12 −5 | waitress/tests/test_functional.py | |
+18 −6 | waitress/tests/test_parser.py | |
+48 −1 | waitress/tests/test_runner.py | |
+10 −4 | waitress/tests/test_server.py | |
+18 −3 | waitress/tests/test_task.py | |
+4 −11 | waitress/trigger.py | |
+5 −1 | waitress/utilities.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.