def PollForMessagesInAnotherThread(filepath, contents): for message in PollForMessages(app, { 'filepath': filepath, 'contents': contents }): if 'filepath' in message and message['filepath'] == filepath: messages_for_filepath.append(message)
def _WaitForDiagnosticsForFile(app, filepath, contents, diags_filepath, diags_are_ready=lambda d: True, **kwargs): diags = None try: for message in PollForMessages(app, { 'filepath': filepath, 'contents': contents }, **kwargs): if ('diagnostics' in message and message['filepath'] == diags_filepath): print('Message {0}'.format(pformat(message))) diags = message['diagnostics'] if diags_are_ready(diags): return diags # Eventually PollForMessages will throw a timeout exception and we'll fail # if we don't see the diagnostics go empty except PollForMessagesTimeoutException as e: raise AssertionError( '{0}. Timed out waiting for diagnostics for file {1}. '.format( e, diags_filepath)) return diags
def FileReadyToParse_Diagnostics_FileNotOnDisk_test(app): StartJavaCompleterServerInDirectory(app, PathToTestFile(DEFAULT_PROJECT_DIR)) contents = ''' package com.test; class Test { public String test } ''' filepath = ProjectPath('Test.java') event_data = BuildRequest(event_name='FileReadyToParse', contents=contents, filepath=filepath, filetype='java') results = app.post_json('/event_notification', event_data).json # This is a new file, so the diagnostics can't possibly be available when the # initial parse request is sent. We receive these asynchronously. eq_(results, {}) diag_matcher = contains( has_entries({ 'kind': 'ERROR', 'text': 'Syntax error, insert ";" to complete ClassBodyDeclarations', 'location': LocationMatcher(filepath, 4, 21), 'location_extent': RangeMatch(filepath, (4, 21), (4, 25)), 'ranges': contains(RangeMatch(filepath, (4, 21), (4, 25))), 'fixit_available': False })) # Poll until we receive the diags for message in PollForMessages(app, { 'filepath': filepath, 'contents': contents }): if 'diagnostics' in message and message['filepath'] == filepath: print('Message {0}'.format(pformat(message))) assert_that( message, has_entries({ 'diagnostics': diag_matcher, 'filepath': filepath })) break # Now confirm that we _also_ get these from the FileReadyToParse request for tries in range(0, 60): results = app.post_json('/event_notification', event_data).json if results: break time.sleep(0.5) print('completer response: {0}'.format(pformat(results))) assert_that(results, diag_matcher)
def PollForMessagesInAnotherThread( filepath, contents ): try: for message in PollForMessages( app, { 'filepath': filepath, 'contents': contents } ): if 'filepath' in message and message[ 'filepath' ] == filepath: messages_for_filepath.append( message ) except PollForMessagesTimeoutException: pass
def Poll_Diagnostics_ProjectWide_Eclipse_test(app): filepath = TestLauncher contents = ReadFile(filepath) # Poll until we receive _all_ the diags asynchronously to_see = sorted(iterkeys(DIAG_MATCHERS_PER_FILE)) seen = dict() try: for message in PollForMessages(app, { 'filepath': filepath, 'contents': contents }): print('Message {0}'.format(pformat(message))) if 'diagnostics' in message: seen[message['filepath']] = True if message['filepath'] not in DIAG_MATCHERS_PER_FILE: raise AssertionError( 'Received diagnostics for unexpected file {0}. ' 'Only expected {1}'.format(message['filepath'], to_see)) assert_that( message, has_entries({ 'diagnostics': DIAG_MATCHERS_PER_FILE[message['filepath']], 'filepath': message['filepath'] })) if sorted(iterkeys(seen)) == to_see: break else: print('Seen diagnostics for {0}, still waiting for {1}'.format( json.dumps(sorted(iterkeys(seen)), indent=2), json.dumps([x for x in to_see if x not in seen], indent=2))) # Eventually PollForMessages will throw a timeout exception and we'll fail # if we don't see all of the expected diags except PollForMessagesTimeoutException as e: raise AssertionError( str(e) + 'Timed out waiting for full set of diagnostics. ' 'Expected to see diags for {0}, but only saw {1}.'.format( json.dumps(to_see, indent=2), json.dumps(sorted(iterkeys(seen)), indent=2)))
def FileReadyToParse_ChangeFileContents_test(app): filepath = TestFactory contents = ReadFile(filepath) StartJavaCompleterServerInDirectory(app, ProjectPath()) # It can take a while for the diagnostics to be ready for tries in range(0, 60): event_data = BuildRequest(event_name='FileReadyToParse', contents=contents, filepath=filepath, filetype='java') results = app.post_json('/event_notification', event_data).json if results: break time.sleep(0.5) # To make the test fair, we make sure there are some results prior to the # 'server not running' call assert results # Call the FileReadyToParse handler but pretend that the server isn't running contents = 'package com.test; class TestFactory {}' # It can take a while for the diagnostics to be ready event_data = BuildRequest(event_name='FileReadyToParse', contents=contents, filepath=filepath, filetype='java') app.post_json('/event_notification', event_data) diags = None try: for message in PollForMessages(app, { 'filepath': filepath, 'contents': contents }): print('Message {0}'.format(pformat(message))) if 'diagnostics' in message and message['filepath'] == filepath: diags = message['diagnostics'] if not diags: break # Eventually PollForMessages will throw a timeout exception and we'll fail # if we don't see the diagnostics go empty except PollForMessagesTimeoutException as e: raise AssertionError( '{0}. Timed out waiting for diagnostics to clear for updated file. ' 'Expected to see none, but diags were: {1}'.format(e, diags)) assert_that(diags, empty()) # Close the file (ensuring no exception) event_data = BuildRequest(event_name='BufferUnload', contents=contents, filepath=filepath, filetype='java') result = app.post_json('/event_notification', event_data).json assert_that(result, equal_to({})) # Close the file again, someone erroneously (ensuring no exception) event_data = BuildRequest(event_name='BufferUnload', contents=contents, filepath=filepath, filetype='java') result = app.post_json('/event_notification', event_data).json assert_that(result, equal_to({}))