def LaunchCTDCommand(args, command): """Launches the specified chromoting test driver command. Args: args: Command line args, used for test-case startup tasks. command: Chromoting Test Driver command line. Returns: "command" if there was a test environment failure, otherwise a string of the names of failed tests. """ TestCaseSetup(args) results = RunCommandInSubProcess(command) tear_down_index = results.find(TEST_ENVIRONMENT_TEAR_DOWN_INDICATOR) if tear_down_index == -1: # The test environment did not tear down. Something went horribly wrong. return '[Command failed]: ' + command end_results_list = results[tear_down_index:].split('\n') failed_tests_list = [] for result in end_results_list: if result.startswith(FAILED_INDICATOR): failed_tests_list.append(result) if failed_tests_list: test_result = '[Command]: ' + command # Note: Skipping the first one is intentional. for i in range(1, len(failed_tests_list)): test_result += ' ' + failed_tests_list[i] return test_result # All tests passed! return ''
def LaunchCTDCommand(args, command): """Launches the specified chromoting test driver command. Args: args: Command line args, used for test-case startup tasks. command: Chromoting Test Driver command line. Returns: command, host_log_file_names: Tuple of: "command" if there was a test-environment failure, or any failing test, and list of host-log file-names. """ host_log_file_names = [] host_log_file_names.append(TestCaseSetup(args)) # Parse the me2me host log to obtain the JID that the host registered. host_jid = GetJidFromHostLog(host_log_file_names[-1]) if not host_jid: # Host-JID not found in log. Let's not attempt to run this test. print 'Host-JID not found in log %s.' % host_log_file_names[-1] return '[Command failed]: %s, %s' % (command, host_log_file_names) retries = 0 failed_tests_list = [] # TODO(anandc): Remove this retry-logic once http://crbug/570840 is fixed. while retries <= MAX_RETRIES: # In order to ensure the host is online with the expected JID, pass in the # jid obtained from the host-log as a command-line parameter. command = command.replace('\n', '') + ' --hostjid=%s' % host_jid results = RunCommandInSubProcess(command) tear_down_index = results.find(TEST_ENVIRONMENT_TEAR_DOWN_INDICATOR) if tear_down_index == -1: # The test environment did not tear down. Something went horribly wrong. return '[Command failed]: ' + command, host_log_file_names end_results_list = results[tear_down_index:].split('\n') test_failed = False for result in end_results_list: if result.startswith(FAILED_INDICATOR): test_failed = True if retries == MAX_RETRIES: # Test failed and we have no more retries left. failed_tests_list.append(result) if test_failed: retries += 1 else: break if failed_tests_list: test_result = '[Command]: ' + command # Note: Skipping the first one is intentional. for i in range(1, len(failed_tests_list)): test_result += ' ' + failed_tests_list[i] return test_result, host_log_file_names # All tests passed! return '', host_log_file_names
def LaunchBTCommand(args, command): """Launches the specified browser-test command. If the execution failed because a browser-instance was not launched, retry once. Args: args: Command line args, used for test-case startup tasks. command: Browser-test command line. """ global TEST_FAILURE, FAILING_TESTS retries = 0 while retries <= MAX_RETRIES: TestCaseSetup(args) results = RunCommandInSubProcess(command) if SUCCESS_INDICATOR in results: # Test passed. break # Sometimes, during execution of browser-tests, a browser instance is # not started and the test times out. See http://crbug/480025. # To work around it, check if this execution failed owing to that # problem and retry. # There are 2 things to look for in the results: # A line saying "Still waiting for the following processes to finish", # and, because sometimes that line gets logged even if the test # eventually passes, we'll also look for "(TIMED OUT)", before retrying. if not (BROWSER_NOT_STARTED_ERROR in results and TIME_OUT_INDICATOR in results): # Test failed for some other reason. Let's not retry. break retries += 1 # Check that the test passed. if SUCCESS_INDICATOR not in results: TEST_FAILURE = True # Add this command-line to list of tests that failed. FAILING_TESTS += command
def LaunchBTCommand(args, command): """Launches the specified browser-test command. Retry if the execution failed because a browser-instance was not launched or because the JID used did not match the host-JID. Args: args: Command line args, used for test-case startup tasks. command: Browser-test command line. Returns: host_log_file_names: Array of host logs created for this command, including retries. """ global TEST_FAILURE, FAILING_TESTS host_log_file_names = [] retries = 0 host_jid_mismatch = False host_jid = None while retries <= MAX_RETRIES: # TestCaseSetup restarts the me2me host, and sets up user-profile dir. # It returns the file-name of the me2me host log. # If we are attempting to run this test because of a JID-mismatch, don't # restart host. if host_jid_mismatch: # Cleanup user-profile directory, but don't restart host. CleanupUserProfileDir(args) else: host_log_file_names.append(TestCaseSetup(args)) # Parse the me2me host log to obtain the JID that the host registered. host_jid = GetJidFromHostLog(host_log_file_names[retries]) results = RunCommandInSubProcess(command) # Get the JID used by this test to connect a remote-host, if any. jids_used = GetJidListFromTestResults(results) # Check for JID mismatch before checking for test success, so that we may # record instances where a test passed despite a JID mismatch. if jids_used and host_jid.rstrip() not in jids_used: host_jid_mismatch = True print('Host JID mismatch. JID in host log = %s.' % host_jid.rstrip()) print('Host JIDs used by test:') for jid in jids_used: print(jid) if host_jid_mismatch: # The JID for the remote-host did not match the JID that was used for this # execution of the test. This happens because of a replication delay in # updating all instances of the Chromoting Directory Server. To # work-around this, sleep for 30s, which, based off a recent (08/2015) # query for average replication delay for Chromoting, should be sufficient # for the current JID value to have fully propagated. retries += 1 time.sleep(30) continue elif jids_used: print('JID used by test matched me2me host JID: %s' % host_jid) else: # There wasn't a mismatch and no JIDs were returned. If no JIDs were # returned, that means the test didn't use any JIDs, so there is nothing # further for us to do. pass if SUCCESS_INDICATOR in results: break # Sometimes, during execution of browser-tests, a browser instance is # not started and the test times out. See http://crbug/480025. # To work around it, check if this execution failed owing to that # problem and retry. # There are 2 things to look for in the results: # A line saying "Still waiting for the following processes to finish", # and, because sometimes that line gets logged even if the test # eventually passes, we'll also look for "(TIMED OUT)", before retrying. if BROWSER_NOT_STARTED_ERROR in results and TIME_OUT_INDICATOR in results: print('Browser-instance not started (http://crbug/480025). Retrying.') else: print('Test failed for unknown reason. Retrying.') retries += 1 # Check that the test passed. if SUCCESS_INDICATOR not in results: TEST_FAILURE = True # Add this command-line to list of tests that failed. FAILING_TESTS += command return host_log_file_names