def trigger_task(swarming_url, progress, unique, timeout, index):
  """Triggers a Swarming job and collects results.

  Returns the total amount of time to run a task remotely, including all the
  overhead.
  """
  name = 'load-test-%d-%s' % (index, unique)
  start = time.time()

  logging.info('trigger')
  manifest = swarming.Manifest(
      None, name, 1, None, swarming_load_test_bot.OS_NAME, '',
      'http://localhost:1', False, False, 100, None)
  data = {'request': manifest.to_json()}
  response = net.url_open(swarming_url + '/test', data=data)
  if not response:
    # Failed to trigger. Return a failure.
    return 'failed_trigger'
  result = json.load(response)
  test_key = result['test_keys'][0].pop('test_key')
  assert test_key
  expected = {
    'test_case_name': name,
    'test_keys': [
      {
        'config_name': swarming_load_test_bot.OS_NAME,
        'num_instances': 1,
        'instance_index': 0,
      },
    ],
  }
  assert result == expected, result
  progress.update_item('%5d' % index, processing=1)
  try:
    logging.info('collect')
    test_keys = swarming.get_test_keys(swarming_url, name)
    if not test_keys:
      return 'no_test_keys'
    assert test_keys == [test_key], test_keys
    out = [
      output
      for _index, output in swarming.yield_results(
          swarming_url, test_keys, timeout, None)
    ]
    if not out:
      return 'no_result'
    out[0].pop('machine_tag')
    out[0].pop('machine_id')
    expected = [
      {
        u'config_instance_index': 0,
        u'exit_codes': u'0',
        u'num_config_instances': 1,
        u'output': swarming_load_test_bot.TASK_OUTPUT,
      },
    ]
    assert out == expected, '\n%s\n%s' % (out, expected)
    return time.time() - start
  finally:
    progress.update_item('%5d - done' % index, processing=-1, processed=1)
示例#2
0
 def test_no_keys(self):
     self.mock(swarming.time, 'sleep', lambda x: x)
     self.requests = [(
         'http://host:9001/get_matching_test_cases?name=my_test',
         {
             'retry_404': True
         },
         StringIO.StringIO('No matching Test Cases'),
     ) for _ in range(net.URL_OPEN_MAX_ATTEMPTS)]
     try:
         swarming.get_test_keys('http://host:9001', 'my_test')
         self.fail()
     except swarming.Failure as e:
         msg = (
             'Error: Unable to find any tests with the name, my_test, on swarm '
             'server')
         self.assertEqual(msg, e.args[0])
示例#3
0
 def test_no_keys(self):
   self.mock(swarming.time, 'sleep', lambda x: x)
   self.requests = [
     (
       'http://host:9001/get_matching_test_cases?name=my_test',
       {'retry_404': True},
       StringIO.StringIO('No matching Test Cases'),
     ) for _ in range(net.URL_OPEN_MAX_ATTEMPTS)
   ]
   try:
     swarming.get_test_keys('http://host:9001', 'my_test')
     self.fail()
   except swarming.Failure as e:
     msg = (
         'Error: Unable to find any tests with the name, my_test, on swarm '
         'server')
     self.assertEqual(msg, e.args[0])
示例#4
0
 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},
       StringIO.StringIO(json.dumps(keys)),
     ),
   ]
   actual = swarming.get_test_keys('http://host:9001', 'my_test')
   self.assertEqual(keys, actual)
示例#5
0
 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
             },
             StringIO.StringIO(json.dumps(keys)),
         ),
     ]
     actual = swarming.get_test_keys('http://host:9001', 'my_test')
     self.assertEqual(keys, actual)
示例#6
0
 def test_no_keys_on_first_attempt(self):
   self.mock(swarming.time, 'sleep', lambda x: x)
   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 = swarming.get_test_keys('http://host:9001', 'my_test')
   self.assertEqual(keys, actual)
示例#7
0
 def test_no_keys_on_first_attempt(self):
     self.mock(swarming.time, 'sleep', lambda x: x)
     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 = swarming.get_test_keys('http://host:9001', 'my_test')
     self.assertEqual(keys, actual)