diff --git a/python/ycm/completers/cs/cs_completer.py b/python/ycm/completers/cs/cs_completer.py index ac33ea57..de6a7937 100755 --- a/python/ycm/completers/cs/cs_completer.py +++ b/python/ycm/completers/cs/cs_completer.py @@ -332,7 +332,7 @@ class CsharpCompleter( Completer ): """ Check if our OmniSharp server is ready """ try: return bool( self._omnisharp_port and - self._GetResponse( '/checkreadystatus', silent = True ) ) + self._GetResponse( '/checkreadystatus', silent = True ) ) except: return False diff --git a/python/ycm/server/tests/diagnostics_test.py b/python/ycm/server/tests/diagnostics_test.py index 9b1b779c..2cb80ed4 100644 --- a/python/ycm/server/tests/diagnostics_test.py +++ b/python/ycm/server/tests/diagnostics_test.py @@ -21,7 +21,7 @@ from ..server_utils import SetUpPythonPath SetUpPythonPath() import time from .test_utils import ( Setup, BuildRequest, PathToTestFile, - StopOmniSharpServer ) + StopOmniSharpServer, WaitUntilOmniSharpServerReady ) from webtest import TestApp from nose.tools import with_setup, eq_ from hamcrest import ( assert_that, contains, contains_string, has_entries, @@ -149,16 +149,7 @@ def Diagnostics_CsCompleter_ZeroBasedLineAndColumn_test(): event_name = 'FileReadyToParse' ) results = app.post_json( '/event_notification', event_data ) - - # We need to wait until the server has started up. - while True: - result = app.post_json( '/run_completer_command', - BuildRequest( completer_target = 'filetype_default', - command_arguments = ['ServerReady'], - filetype = 'cs' ) ).json - if result: - break - time.sleep( 0.2 ) + WaitUntilOmniSharpServerReady( app ) event_data = BuildRequest( filepath = filepath, event_name = 'FileReadyToParse', @@ -230,17 +221,7 @@ def GetDetailedDiagnostic_CsCompleter_Works_test(): event_name = 'FileReadyToParse' ) app.post_json( '/event_notification', event_data ) - - # We need to wait until the server has started up. - while True: - result = app.post_json( '/run_completer_command', - BuildRequest( completer_target = 'filetype_default', - command_arguments = ['ServerReady'], - filetype = 'cs' ) ).json - if result: - break - time.sleep( 0.2 ) - + WaitUntilOmniSharpServerReady( app ) app.post_json( '/event_notification', event_data ) diag_data = BuildRequest( filepath = filepath, diff --git a/python/ycm/server/tests/get_completions_test.py b/python/ycm/server/tests/get_completions_test.py index 9607dc36..0e8d6a98 100644 --- a/python/ycm/server/tests/get_completions_test.py +++ b/python/ycm/server/tests/get_completions_test.py @@ -19,10 +19,10 @@ from ..server_utils import SetUpPythonPath SetUpPythonPath() -import time import httplib from .test_utils import ( Setup, BuildRequest, PathToTestFile, - ChangeSpecificOptions, StopOmniSharpServer ) + ChangeSpecificOptions, StopOmniSharpServer, + WaitUntilOmniSharpServerReady ) from webtest import TestApp, AppError from nose.tools import eq_, with_setup from hamcrest import ( assert_that, has_item, has_items, has_entry, @@ -68,16 +68,7 @@ def GetCompletions_CsCompleter_Works_test(): event_name = 'FileReadyToParse' ) app.post_json( '/event_notification', event_data ) - - # We need to wait until the server has started up. - while True: - result = app.post_json( '/run_completer_command', - BuildRequest( completer_target = 'filetype_default', - command_arguments = ['ServerReady'], - filetype = 'cs' ) ).json - if result: - break - time.sleep( 0.2 ) + WaitUntilOmniSharpServerReady( app ) completion_data = BuildRequest( filepath = filepath, filetype = 'cs', @@ -103,25 +94,13 @@ def GetCompletions_CsCompleter_ReloadSolutionWorks_test(): event_name = 'FileReadyToParse' ) app.post_json( '/event_notification', event_data ) - - # We need to wait until the server has started up. - while True: - result = app.post_json( '/run_completer_command', - BuildRequest( completer_target = 'filetype_default', - command_arguments = ['ServerReady'], - filetype = 'cs' ) ).json - if result: - break - time.sleep( 0.2 ) - - + WaitUntilOmniSharpServerReady( app ) result = app.post_json( '/run_completer_command', BuildRequest( completer_target = 'filetype_default', command_arguments = ['ReloadSolution'], filetype = 'cs' ) ).json eq_(result, True) - StopOmniSharpServer( app ) @with_setup( Setup ) @@ -139,16 +118,7 @@ def GetCompletions_CsCompleter_StartsWithUnambiguousMultipleSolutions_test(): # Here the server will raise an exception if it can't start app.post_json( '/event_notification', event_data ) - # Now for some cleanup: wait for the server to start then shut it down - while True: - result = app.post_json( '/run_completer_command', - BuildRequest( completer_target = 'filetype_default', - command_arguments = ['ServerRunning'], - filetype = 'cs' ) ).json - if result: - break - time.sleep( 0.2 ) - + WaitUntilOmniSharpServerReady( app ) StopOmniSharpServer( app ) @with_setup( Setup ) @@ -173,6 +143,7 @@ def GetCompletions_CsCompleter_DoesntStartWithAmbiguousMultipleSolutions_test(): # the test passes if we caught an exception when trying to start it, # so raise one if it managed to start if not exception_caught: + WaitUntilOmniSharpServerReady( app ) StopOmniSharpServer( app ) raise Exception( ('The Omnisharp server started, despite us not being able ' 'to find a suitable solution file to feed it. Did you ' diff --git a/python/ycm/server/tests/test_utils.py b/python/ycm/server/tests/test_utils.py index 0ef7ff37..676e6842 100644 --- a/python/ycm/server/tests/test_utils.py +++ b/python/ycm/server/tests/test_utils.py @@ -18,6 +18,7 @@ # along with YouCompleteMe. If not, see . import os +import time from .. import handlers from ycm import user_options_store @@ -80,3 +81,15 @@ def StopOmniSharpServer( app ): BuildRequest( completer_target = 'filetype_default', command_arguments = ['StopServer'], filetype = 'cs' ) ) + +def WaitUntilOmniSharpServerReady( app ): + while True: + result = app.post_json( '/run_completer_command', + BuildRequest( completer_target = 'filetype_default', + command_arguments = ['ServerReady'], + filetype = 'cs' ) ).json + if result: + break + time.sleep( 0.2 ) + +