def test_find_keys(self):
   keys = ['key_1', 'key_2']
   self.requests = [
     (
       'http://host:9001/get_matching_test_cases?name=my_test',
       {'retry_404': True, 'timeout': 0.0},
       StringIO.StringIO(json.dumps(keys)),
     ),
   ]
   actual = swarm_get_results.get_test_keys('http://host:9001', 'my_test', 0.)
   self.assertEqual(keys, actual)
 def test_no_keys(self):
   old_sleep = swarm_get_results.time.sleep
   swarm_get_results.time.sleep = lambda x: x
   try:
     self.requests = [
       (
         'http://host:9001/get_matching_test_cases?name=my_test',
         {'retry_404': True, 'timeout': 0.0},
         StringIO.StringIO('No matching Test Cases'),
       ) for _ in range(run_isolated.URL_OPEN_MAX_ATTEMPTS)
     ]
     try:
       swarm_get_results.get_test_keys('http://host:9001', 'my_test', 0.)
       self.fail()
     except swarm_get_results.Failure as e:
       msg = (
           'Error: Unable to find any tests with the name, my_test, on swarm '
           'server')
       self.assertEqual(msg, e.args[0])
   finally:
     swarm_get_results.time.sleep = old_sleep
예제 #3
0
def v0(client, options, test_name):
    """This code supports all the earliest versions of swarm_client.

  This is before --version was added.
  """
    sys.path.insert(0, client)
    import swarm_get_results  # pylint: disable=F0401

    timeout = swarm_get_results.DEFAULT_SHARD_WAIT_TIME
    test_keys = swarm_get_results.get_test_keys(options.swarming, test_name,
                                                timeout)
    if not test_keys:
        print >> sys.stderr, 'No test keys to get results with.'
        return 1

    if options.shards == -1:
        options.shards = len(test_keys)
    elif len(test_keys) < options.shards:
        print >> sys.stderr, (
            'Warning: Test should have %d shards, but only %d '
            'test keys were found' % (options.shards, len(test_keys)))

    gtest_parser = gtest_utils.GTestLogParser()
    exit_code = None
    shards_remaining = range(len(test_keys))
    first_result = True
    for index, result in swarm_get_results.yield_results(
            options.swarming, test_keys, timeout, None):
        assert index == result['config_instance_index']
        if first_result and result['num_config_instances'] != len(test_keys):
            # There are more test_keys than actual shards.
            shards_remaining = shards_remaining[:
                                                result['num_config_instances']]
        shards_remaining.remove(index)
        first_result = False
        output, test_exit_code = gen_shard_output(result, gtest_parser)
        print output
        exit_code = max(exit_code, test_exit_code)

    # Print the annotation before the summary so it's easier to find when scolling
    # down.
    annotation_utils.annotate(test_name, exit_code, gtest_parser)
    print('')
    return exit_code
def v0(client, options, test_name):
  """This code supports all the earliest versions of swarm_client.

  This is before --version was added.
  """
  sys.path.insert(0, client)
  import swarm_get_results  # pylint: disable=F0401

  timeout = swarm_get_results.DEFAULT_SHARD_WAIT_TIME
  test_keys = swarm_get_results.get_test_keys(
      options.swarming, test_name, timeout)
  if not test_keys:
    print >> sys.stderr, 'No test keys to get results with.'
    return 1

  if options.shards == -1:
    options.shards = len(test_keys)
  elif len(test_keys) < options.shards:
    print >> sys.stderr, ('Warning: Test should have %d shards, but only %d '
                          'test keys were found' % (options.shards,
                                                    len(test_keys)))

  gtest_parser = gtest_utils.GTestLogParser()
  exit_code = None
  shards_remaining = range(len(test_keys))
  first_result = True
  for index, result in swarm_get_results.yield_results(
      options.swarming, test_keys, timeout, None):
    assert index == result['config_instance_index']
    if first_result and result['num_config_instances'] != len(test_keys):
      # There are more test_keys than actual shards.
      shards_remaining = shards_remaining[:result['num_config_instances']]
    shards_remaining.remove(index)
    first_result = False
    output, test_exit_code = gen_shard_output(result, gtest_parser)
    print output
    exit_code = max(exit_code, test_exit_code)

  # Print the annotation before the summary so it's easier to find when scolling
  # down.
  annotation_utils.annotate(test_name, exit_code, gtest_parser)
  print('')
  return exit_code
 def test_no_keys_on_first_attempt(self):
   old_sleep = swarm_get_results.time.sleep
   swarm_get_results.time.sleep = lambda x: x
   try:
     keys = ['key_1', 'key_2']
     self.requests = [
       (
         'http://host:9001/get_matching_test_cases?name=my_test',
         {'retry_404': True},
         StringIO.StringIO('No matching Test Cases'),
       ),
       (
         'http://host:9001/get_matching_test_cases?name=my_test',
         {'retry_404': True},
         StringIO.StringIO(json.dumps(keys)),
       ),
     ]
     actual = swarm_get_results.get_test_keys('http://host:9001', 'my_test')
     self.assertEqual(keys, actual)
   finally:
     swarm_get_results.time.sleep = old_sleep
 def test_no_keys_on_first_attempt(self):
   old_sleep = swarm_get_results.time.sleep
   swarm_get_results.time.sleep = lambda x: x
   try:
     keys = ['key_1', 'key_2']
     self.requests = [
       (
         'http://host:9001/get_matching_test_cases?name=my_test',
         {'retry_404': True, 'timeout': 0.0},
         StringIO.StringIO('No matching Test Cases'),
       ),
       (
         'http://host:9001/get_matching_test_cases?name=my_test',
         {'retry_404': True, 'timeout': 0.0},
         StringIO.StringIO(json.dumps(keys)),
       ),
     ]
     actual = swarm_get_results.get_test_keys('http://host:9001', 'my_test',
                                              0.)
     self.assertEqual(keys, actual)
   finally:
     swarm_get_results.time.sleep = old_sleep
예제 #7
0
def main():
  src_swarming_client = os.path.join(
      os.getcwd(), 'src', 'tools', 'swarming_client')

  # This is the previous path. This can be removed around 2013-12-01.
  src_swarm_client = os.path.join(os.getcwd(), 'src', 'tools', 'swarm_client')

  if os.path.isdir(src_swarming_client):
    sys.path.insert(0, src_swarming_client)
  elif os.path.isdir(src_swarm_client):
    sys.path.insert(0, src_swarm_client)
  else:
    print >> sys.stderr, 'Failed to find swarm_client at %s or %s' % (
        src_swarming_client, src_swarm_client)
    return 1

  import swarm_get_results  # pylint: disable=F0401

  parser, options, test_name = swarm_get_results.parse_args()
  if not options.shards:
    parser.error('The number of shards expected must be passed in.')
  test_keys = swarm_get_results.get_test_keys(
      options.url, test_name, options.timeout)
  if not test_keys:
    parser.error('No test keys to get results with.')

  options.shards = int(options.shards)
  if options.shards == -1:
    options.shards = len(test_keys)
  elif len(test_keys) < options.shards:
    print >> sys.stderr, ('Warning: Test should have %d shards, but only %d '
                          'test keys were found' % (options.shards,
                                                    len(test_keys)))

  return GetSwarmResults(
      swarm_get_results, options.url, test_keys, options.timeout, None)