original_docstring: Reads JSON test output from all shards and combines them into one.
  
    Returns dict with merged test output on success or None on failure. Emits
    annotations.
    
docstring: Reads JSON test output from all shards and combines them into one.
  Returns dict with merged test output on success or None on failure. Emits
  annotations.
docstring_tokens: Reads JSON test output from all shards and combines them into one . Returns dict with merged test output on success or None on failure . Emits annotations .
code: def merge_shard_results(summary_json, jsons_to_merge):
    """Reads JSON test output from all shards and combines them into one.
  
    Returns dict with merged test output on success or None on failure. Emits
    annotations.
    """
    try:
      with open(summary_json) as f:
        summary = json.load(f)
    except (IOError, ValueError):
      # TODO(crbug.com/1245494):Re-enable this check after the recipe module
      # chromium_swarming can run it with py3
      # pylint: disable=raise-missing-from
      raise Exception('Summary json cannot be loaded.')
  
    # Merge all JSON files together. Keep track of missing shards.
    merged = {
      'all_tests': set(),
      'disabled_tests': set(),
      'global_tags': set(),
      'missing_shards': [],
      'per_iteration_data': [],
      'swarming_summary': summary,
      'links': set()
    }
    for index, result in enumerate(summary['shards']):
      if result is None:
        merged['missing_shards'].append(index)
        continue
  
      # Author note: this code path doesn't trigger convert_to_old_format() in
      # client/swarming.py, which means the state enum is saved in its string
      # name form, not in the number form.
      state = result.get('state')
      if state == 'BOT_DIED':
        print(
            'Shard #%d had a Swarming internal failure' % index, file=sys.stderr)
      elif state == 'EXPIRED':
        print('There wasn\'t enough capacity to run your test', file=sys.stderr)
      elif state == 'TIMED_OUT':
        print('Test runtime exceeded allocated time'
              'Either it ran for too long (hard timeout) or it didn\'t produce '
              'I/O for an extended period of time (I/O timeout)',
              file=sys.stderr)
      elif state != 'COMPLETED':
        print('Invalid Swarming task state: %s' % state, file=sys.stderr)
  
      json_data, err_msg = load_shard_json(index, result.get('task_id'),
                                           jsons_to_merge)
      if json_data:
        # Set-like fields.
        for key in ('all_tests', 'disabled_tests', 'global_tags', 'links'):
          merged[key].update(json_data.get(key), [])
  
        # 'per_iteration_data' is a list of dicts. Dicts should be merged
        # together, not the 'per_iteration_data' list itself.
        merged['per_iteration_data'] = merge_list_of_dicts(
            merged['per_iteration_data'], json_data.get('per_iteration_data', []))
      else:
        merged['missing_shards'].append(index)
        print('No result was found: %s' % err_msg, file=sys.stderr)
  
    # If some shards are missing, make it known. Continue parsing anyway. Step
    # should be red anyway, since swarming.py return non-zero exit code in that
    # case.
    if merged['missing_shards']:
      as_str = ', '.join([str(shard) for shard in merged['missing_shards']])
      print('some shards did not complete: %s' % as_str, file=sys.stderr)
      # Not all tests run, combined JSON summary can not be trusted.
      merged['global_tags'].add('UNRELIABLE_RESULTS')
  
    # Convert to jsonish dict.
    for key in ('all_tests', 'disabled_tests', 'global_tags', 'links'):
      merged[key] = sorted(merged[key])
    return merged
code_tokens: def merge_shard_results ( summary_json , jsons_to_merge ) : try : with open ( summary_json ) as f : summary = json . load ( f ) except ( IOError , ValueError ) : raise Exception ( 'Summary json cannot be loaded.' ) merged = { 'all_tests' : set ( ) , 'disabled_tests' : set ( ) , 'global_tags' : set ( ) , 'missing_shards' : [ ] , 'per_iteration_data' : [ ] , 'swarming_summary' : summary , 'links' : set ( ) } for index , result in enumerate ( summary [ 'shards' ] ) : if result is None : merged [ 'missing_shards' ] . append ( index ) continue state = result . get ( 'state' ) if state == 'BOT_DIED' : print ( 'Shard #%d had a Swarming internal failure' % index , file = sys . stderr ) elif state == 'EXPIRED' : print ( 'There wasn\'t enough capacity to run your test' , file = sys . stderr ) elif state == 'TIMED_OUT' : print ( 'Test runtime exceeded allocated time' 'Either it ran for too long (hard timeout) or it didn\'t produce ' 'I/O for an extended period of time (I/O timeout)' , file = sys . stderr ) elif state != 'COMPLETED' : print ( 'Invalid Swarming task state: %s' % state , file = sys . stderr ) json_data , err_msg = load_shard_json ( index , result . get ( 'task_id' ) , jsons_to_merge ) if json_data : for key in ( 'all_tests' , 'disabled_tests' , 'global_tags' , 'links' ) : merged [ key ] . update ( json_data . get ( key ) , [ ] ) merged [ 'per_iteration_data' ] = merge_list_of_dicts ( merged [ 'per_iteration_data' ] , json_data . get ( 'per_iteration_data' , [ ] ) ) else : merged [ 'missing_shards' ] . append ( index ) print ( 'No result was found: %s' % err_msg , file = sys . stderr ) if merged [ 'missing_shards' ] : as_str = ', ' . join ( [ str ( shard ) for shard in merged [ 'missing_shards' ] ] ) print ( 'some shards did not complete: %s' % as_str , file = sys . stderr ) merged [ 'global_tags' ] . add ( 'UNRELIABLE_RESULTS' ) for key in ( 'all_tests' , 'disabled_tests' , 'global_tags' , 'links' ) : merged [ key ] = sorted ( merged [ key ] ) return merged
short_docstring: Reads JSON test output from all shards and combines them into one.
short_docstring_tokens: Reads JSON test output from all shards and combines them into one .
comment: """Reads JSON test output from all shards and combines them into one.
  
    Returns dict with merged test output on success or None on failure. Emits
    annotations.
    """$SEP$# TODO(crbug.com/1245494):Re-enable this check after the recipe module$SEP$# chromium_swarming can run it with py3$SEP$# pylint: disable=raise-missing-from$SEP$# Merge all JSON files together. Keep track of missing shards.$SEP$# Author note: this code path doesn't trigger convert_to_old_format() in$SEP$# client/swarming.py, which means the state enum is saved in its string$SEP$# name form, not in the number form.$SEP$# Set-like fields.$SEP$# 'per_iteration_data' is a list of dicts. Dicts should be merged$SEP$# together, not the 'per_iteration_data' list itself.$SEP$# If some shards are missing, make it known. Continue parsing anyway. Step$SEP$# should be red anyway, since swarming.py return non-zero exit code in that$SEP$# case.$SEP$# Not all tests run, combined JSON summary can not be trusted.$SEP$# Convert to jsonish dict.