示例#1
0
def PollingThread(app, messages_for_filepath, filepath, contents):

    done = False

    def PollForMessagesInAnotherThread():
        try:
            for message in PollForMessages(app, {
                    'filepath': filepath,
                    'contents': contents,
                    'filetype': 'java'
            }):
                if done:
                    return

                if 'filepath' in message and message['filepath'] == filepath:
                    messages_for_filepath.append(message)
        except PollForMessagesTimeoutException:
            pass

    try:
        poller = StartThread(PollForMessagesInAnotherThread)
        yield
    finally:
        done = True
        poller.join(120)
        assert not poller.is_alive()
def PollForMessages_AbortedWhenServerDies_test( app ):
  StartJavaCompleterServerInDirectory(
    app,
    PathToTestFile( 'simple_eclipse_project' ) )

  filepath = TestFactory
  contents = ReadFile( filepath )

  def AwaitMessages():
    for tries in range( 0, 5 ):
      response = app.post_json( '/receive_messages',
                                BuildRequest(
                                  filetype = 'java',
                                  filepath = filepath,
                                  contents = contents ) ).json
      if response is False:
        return

    raise AssertionError( 'The poll request was not aborted in 5 tries' )

  message_poll_task = StartThread( AwaitMessages )

  app.post_json(
    '/run_completer_command',
    BuildRequest(
      filetype = 'java',
      command_arguments = [ 'StopServer' ],
    ),
  )

  message_poll_task.join()
示例#3
0
    def FromWatchdogWithSubservers_test(self):
        all_servers_are_running = Event()

        def KeepServerAliveInAnotherThread():
            while not all_servers_are_running.is_set():
                try:
                    self.GetRequest('ready')
                except requests.exceptions.ConnectionError:
                    pass
                finally:
                    time.sleep(0.1)

        self.Start(idle_suicide_seconds=2, check_interval_seconds=1)

        StartThread(KeepServerAliveInAnotherThread)

        try:
            filetypes = [
                'cs', 'go', 'java', 'javascript', 'typescript', 'rust'
            ]
            for filetype in filetypes:
                self.StartSubserverForFiletype(filetype)
            self.AssertServersAreRunning()
        finally:
            all_servers_are_running.set()

        self.AssertServersShutDown(timeout=SUBSERVER_SHUTDOWN_TIMEOUT + 10)
        self.AssertLogfilesAreRemoved()
示例#4
0
文件: handlers.py 项目: inglor/ycmd
def ServerShutdown():
    def Terminator():
        if wsgi_server:
            wsgi_server.shutdown()

    # Use a separate thread to let the server send the response before shutting
    # down.
    StartThread(Terminator)
示例#5
0
文件: handlers.py 项目: inglor/ycmd
def KeepSubserversAlive(check_interval_seconds):
    def Keepalive(check_interval_seconds):
        while True:
            time.sleep(check_interval_seconds)

            LOGGER.debug('Keeping subservers alive')
            loaded_completers = _server_state.GetLoadedFiletypeCompleters()
            for completer in loaded_completers:
                completer.ServerIsHealthy()

    StartThread(Keepalive, check_interval_seconds)
示例#6
0
    def __init__(self, idle_suicide_seconds, check_interval_seconds):
        self._check_interval_seconds = check_interval_seconds
        self._idle_suicide_seconds = idle_suicide_seconds

        # No need for a lock on wakeup time since only the watchdog thread ever
        # reads or sets it.
        self._last_wakeup_time = time.time()
        self._last_request_time = time.time()
        self._last_request_time_lock = Lock()
        if idle_suicide_seconds <= 0:
            return
        StartThread(self._WatchdogMain)
示例#7
0
  def test_PollForMessages_AbortedWhenServerDies( self, app ):
    StartJavaCompleterServerInDirectory(
      app,
      PathToTestFile( 'simple_eclipse_project' ) )

    filepath = TestFactory
    contents = ReadFile( filepath )

    state = {
      'aborted': False
    }

    def AwaitMessages():
      max_tries = 20
      for tries in range( 0, max_tries ):
        response = app.post_json( '/receive_messages',
                                  BuildRequest(
                                    filetype = 'java',
                                    filepath = filepath,
                                    contents = contents ) ).json
        if response is False:
          state[ 'aborted' ] = True
          return

      raise AssertionError(
        f'The poll request was not aborted in { max_tries } tries' )

    message_poll_task = StartThread( AwaitMessages )

    app.post_json(
      '/run_completer_command',
      BuildRequest(
        filetype = 'java',
        command_arguments = [ 'StopServer' ],
      ),
    )

    message_poll_task.join()
    assert_that( state[ 'aborted' ] )
示例#8
0
def Poll_Diagnostics_ChangeFileContents_test( app ):
  StartJavaCompleterServerInDirectory( app,
                                       PathToTestFile( DEFAULT_PROJECT_DIR ) )

  filepath = youcompleteme_Test
  old_contents = """package com.youcompleteme;

public class Test {
  public String test;
}"""

  messages_for_filepath = []

  def PollForMessagesInAnotherThread( filepath, contents ):
    try:
      for message in PollForMessages( app,
                                      { 'filepath': filepath,
                                        'contents': contents,
                                        'filetype': 'java' } ):
        if 'filepath' in message and message[ 'filepath' ] == filepath:
          messages_for_filepath.append( message )
    except PollForMessagesTimeoutException:
      pass

  StartThread( PollForMessagesInAnotherThread, filepath, old_contents )

  new_contents = """package com.youcompleteme;

public class Test {
  public String test;
  public String test;
}"""

  event_data = BuildRequest( event_name = 'FileReadyToParse',
                             contents = new_contents,
                             filepath = filepath,
                             filetype = 'java' )
  app.post_json( '/event_notification', event_data ).json

  expiration = time.time() + 10
  while True:
    try:
      assert_that(
        messages_for_filepath,
        has_item( has_entries( {
          'filepath': filepath,
          'diagnostics': contains(
            has_entries( {
              'kind': 'ERROR',
              'text': 'Duplicate field Test.test',
              'location': LocationMatcher( youcompleteme_Test, 4, 17 ),
              'location_extent': RangeMatcher( youcompleteme_Test,
                                               ( 4, 17 ),
                                               ( 4, 21 ) ),
              'ranges': contains( RangeMatcher( youcompleteme_Test,
                                                ( 4, 17 ),
                                                ( 4, 21 ) ) ),
              'fixit_available': False
            } ),
            has_entries( {
              'kind': 'ERROR',
              'text': 'Duplicate field Test.test',
              'location': LocationMatcher( youcompleteme_Test, 5, 17 ),
              'location_extent': RangeMatcher( youcompleteme_Test,
                                               ( 5, 17 ),
                                               ( 5, 21 ) ),
              'ranges': contains( RangeMatcher( youcompleteme_Test,
                                                ( 5, 17 ),
                                                ( 5, 21 ) ) ),
              'fixit_available': False
            } )
          )
        } ) )
      )
      break
    except AssertionError:
      if time.time() > expiration:
        raise

      time.sleep( 0.25 )