Skip to content

Commit

Permalink
Add method to start subserver in tests
Browse files Browse the repository at this point in the history
Update subserver tests by starting multiple subservers.
  • Loading branch information
micbou committed Jan 10, 2016
1 parent 1f7e4f2 commit 7016b88
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 17 deletions.
44 changes: 44 additions & 0 deletions ycmd/tests/client_test.py
Expand Up @@ -20,6 +20,7 @@
from ycmd.utils import ( GetUnusedLocalhostPort, PathToTempDir,
RemoveIfExists, SafePopen, ToUtf8Json )
from ycmd.hmac_utils import CreateHmac, CreateRequestHmac, SecureStringsEqual
from test_utils import BuildRequest
from base64 import b64encode, b64decode
from hamcrest import assert_that, equal_to, has_length, is_in
import collections
Expand Down Expand Up @@ -134,6 +135,49 @@ def _WaitUntilReady( self, timeout = 5 ):
total_slept += 0.1


def _StartSubserverForFiletype( self, filetype ):
# TODO: uniformize the way subservers are started in completers. Current
# status for each completer is:
# - Clang: no subserver;
# - C#: StartServer/RestartServer commands and FileReadyToParse event;
# - Go: StartServer command and FileReadyToParse event;
# - Javascript: StartServer command and completer initialization;
# - Python: RestartServer command and completer initialization;
# - Rust: RestartServer command and completer initialization;
# - Typescript: completer initialization.

# Completers have different ways to start their subservers. We first
# attempt to start the subserver by using StartServer and RestartServer
# commands. If both commands fail, we send a BufferVisit notification
# as a last resort.
# This is working for all completers with a subserver except C# which
# requires a solution to start.
# NOTE: due to the way Go subserver is started, it will not be a child of
# ycmd server. This is why it is not used in the tests.
response = self._PostRequest(
'run_completer_command',
BuildRequest( command_arguments = [ 'StartServer' ],
filetype = filetype )
)
if response.status_code is httplib.OK:
return response

response = self._PostRequest(
'run_completer_command',
BuildRequest( command_arguments = [ 'RestartServer' ],
filetype = filetype )
)
if response.status_code is httplib.OK:
return response

response = self._PostRequest(
'event_notification',
BuildRequest( event_name = 'BufferVisit',
filetype = filetype )
)
return response


def _AssertServerAndSubserversShutDown( self, timeout = 5 ):
_, alive = psutil.wait_procs( [ self._server ] + self._subservers,
timeout = timeout )
Expand Down
37 changes: 20 additions & 17 deletions ycmd/tests/shutdown_test.py
Expand Up @@ -18,7 +18,6 @@
# along with ycmd. If not, see <http://www.gnu.org/licenses/>.

from hamcrest import assert_that, equal_to, has_length
from test_utils import BuildRequest
from .client_test import Client_test


Expand All @@ -36,19 +35,21 @@ def FromHandlerWithoutSubserver_test( self ):


@Client_test.CaptureOutputFromServer
def FromHandlerWithSubserver_test( self ):
def FromHandlerWithSubservers_test( self ):
self._Start()
self._WaitUntilReady()

response = self._PostRequest(
'run_completer_command',
BuildRequest( command_arguments = [ 'StartServer' ],
filetype = 'javascript' )
)
self._AssertResponse( response )
filetypes = [ 'javascript',
'python',
'rust',
'typescript' ]

for filetype in filetypes:
response = self._StartSubserverForFiletype( filetype )
self._AssertResponse( response )

self._subservers = self._GetSubservers()
assert_that( self._subservers, has_length( equal_to( 1 ) ) )
assert_that( self._subservers, has_length( equal_to( len( filetypes ) ) ) )

response = self._PostRequest( 'shutdown' )
self._AssertResponse( response )
Expand All @@ -65,18 +66,20 @@ def FromWatchdogWithoutSubserver_test( self ):


@Client_test.CaptureOutputFromServer
def FromWatchdogWithSubserver_test( self ):
def FromWatchdogWithSubservers_test( self ):
self._Start( idle_suicide_seconds = 2, check_interval_seconds = 1 )
self._WaitUntilReady()

response = self._PostRequest(
'run_completer_command',
BuildRequest( command_arguments = [ 'StartServer' ],
filetype = 'javascript' )
)
self._AssertResponse( response )
filetypes = [ 'javascript',
'python',
'rust',
'typescript' ]

for filetype in filetypes:
response = self._StartSubserverForFiletype( filetype )
self._AssertResponse( response )

self._subservers = self._GetSubservers()
assert_that( self._subservers, has_length( equal_to( 1 ) ) )
assert_that( self._subservers, has_length( equal_to( len( filetypes ) ) ) )

self._AssertServerAndSubserversShutDown()

0 comments on commit 7016b88

Please sign in to comment.