Skip to content

Commit

Permalink
Separate infrastructure from actual tests
Browse files Browse the repository at this point in the history
Move infrastructure used in shutdown tests to its own class. Since this
is a client implementation, call it Client_test instead of Server_test.
Create a new class Shutdown_test inheriting Client_test.
  • Loading branch information
micbou committed Dec 23, 2015
1 parent 638125c commit 7e9177f
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 58 deletions.
61 changes: 3 additions & 58 deletions ycmd/tests/server_test.py → ycmd/tests/client_test.py
Expand Up @@ -21,8 +21,7 @@
RemoveIfExists, SafePopen, ToUtf8Json )
from ycmd.hmac_utils import CreateHmac, CreateRequestHmac, SecureStringsEqual
from base64 import b64encode, b64decode
from hamcrest import assert_that, equal_to, greater_than, has_length, is_in
from test_utils import BuildRequest
from hamcrest import assert_that, equal_to, has_length, is_in
import collections
import sys
import json
Expand All @@ -41,7 +40,7 @@
PATH_TO_YCMD = os.path.join( DIR_OF_THIS_SCRIPT, '..' )


class Server_test( object ):
class Client_test( object ):

def __init__( self ):
self._location = None
Expand Down Expand Up @@ -69,60 +68,6 @@ def tearDown( self ):
subserver.terminate()


def ShutdownWithNoSubserver_test( self ):
self._Start()
self._WaitUntilReady()

response = self._PostRequest( 'shutdown' )
self._AssertResponse( response )

self._AssertServerAndSubserversShutdown()


def ShutdownWithSubserver_test( self ):
self._Start()
self._WaitUntilReady()

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

self._subservers = self._GetSubservers()
assert_that( self._subservers, has_length( greater_than( 0 ) ) )

response = self._PostRequest( 'shutdown' )
self._AssertResponse( response )

self._AssertServerAndSubserversShutdown()


def WatchdogWithNoSubserver_test( self ):
self._Start( idle_suicide_seconds = 2, check_interval_seconds = 1 )
self._WaitUntilReady()

self._AssertServerAndSubserversShutdown()


def WatchdogWithSubserver_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 )

self._subservers = self._GetSubservers()
assert_that( self._subservers, has_length( greater_than( 0 ) ) )

self._AssertServerAndSubserversShutdown()


def _Start( self, idle_suicide_seconds = 60,
check_interval_seconds = 60 * 10 ):
# The temp options file is deleted by ycmd during startup
Expand Down Expand Up @@ -188,7 +133,7 @@ def _WaitUntilReady( self, timeout = 5 ):
total_slept += 0.1


def _AssertServerAndSubserversShutdown( self, timeout = 5 ):
def _AssertServerAndSubserversShutDown( self, timeout = 5 ):
_, alive = psutil.wait_procs( [ self._server ] + self._subservers,
timeout = timeout )
assert_that( alive, has_length( equal_to( 0 ) ) )
Expand Down
78 changes: 78 additions & 0 deletions ycmd/tests/shutdown_test.py
@@ -0,0 +1,78 @@
#!/usr/bin/env python
#
# Copyright (C) 2015 ycmd contributors
#
# This file is part of ycmd.
#
# ycmd is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ycmd is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ycmd. If not, see <http://www.gnu.org/licenses/>.

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


class Shutdown_test( Client_test ):

def FromHandlerWithNoSubserver_test( self ):
self._Start()
self._WaitUntilReady()

response = self._PostRequest( 'shutdown' )
self._AssertResponse( response )

self._AssertServerAndSubserversShutDown()


def FromHandlerWithSubserver_test( self ):
self._Start()
self._WaitUntilReady()

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

self._subservers = self._GetSubservers()
assert_that( self._subservers, has_length( greater_than( 0 ) ) )

response = self._PostRequest( 'shutdown' )
self._AssertResponse( response )

self._AssertServerAndSubserversShutDown()


def FromWatchdogWithNoSubserver_test( self ):
self._Start( idle_suicide_seconds = 2, check_interval_seconds = 1 )
self._WaitUntilReady()

self._AssertServerAndSubserversShutDown()


def FromWatchdogWithSubserver_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 )

self._subservers = self._GetSubservers()
assert_that( self._subservers, has_length( greater_than( 0 ) ) )

self._AssertServerAndSubserversShutDown()

0 comments on commit 7e9177f

Please sign in to comment.