Example #1
0
 def test_no_keys(self):
     self.mock(swarming.time, "sleep", lambda x: x)
     self.requests = [
         ("/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_task_keys("http://host:9001", "my_test")
         self.fail()
     except swarming.Failure as e:
         msg = "Error: Unable to find any task with the name, my_test, on swarming " "server"
         self.assertEqual(msg, e.args[0])
Example #2
0
 def test_find_keys(self):
     keys = ["key_1", "key_2"]
     self.requests = [
         ("/get_matching_test_cases?name=my_test", {"retry_404": True}, StringIO.StringIO(json.dumps(keys)))
     ]
     actual = swarming.get_task_keys("http://host:9001", "my_test")
     self.assertEqual(keys, actual)
 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_task_keys('http://host:9001', 'my_test')
     self.fail()
   except swarming.Failure as e:
     msg = (
         'Error: Unable to find any task with the name, my_test, on swarming '
         'server')
     self.assertEqual(msg, e.args[0])
Example #4
0
 def test_no_keys(self):
   self.mock(swarming.time, 'sleep', lambda x: x)
   self.requests = [
     (
       '/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_task_keys('http://host:9001', 'my_test')
     self.fail()
   except swarming.Failure as e:
     msg = (
         'Error: Unable to find any task with the name, my_test, on swarming '
         'server')
     self.assertEqual(msg, e.args[0])
Example #5
0
 def test_no_keys_on_first_attempt(self):
     self.mock(swarming.time, "sleep", lambda x: x)
     keys = ["key_1", "key_2"]
     self.requests = [
         ("/get_matching_test_cases?name=my_test", {"retry_404": True}, StringIO.StringIO("No matching Test Cases")),
         ("/get_matching_test_cases?name=my_test", {"retry_404": True}, StringIO.StringIO(json.dumps(keys))),
     ]
     actual = swarming.get_task_keys("http://host:9001", "my_test")
     self.assertEqual(keys, actual)
 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_task_keys('http://host:9001', 'my_test')
   self.assertEqual(keys, actual)
Example #7
0
 def test_find_keys(self):
   keys = ['key_1', 'key_2']
   self.requests = [
     (
       '/get_matching_test_cases?name=my_test',
       {'retry_404': True},
       StringIO.StringIO(json.dumps(keys)),
     ),
   ]
   actual = swarming.get_task_keys('http://host:9001', 'my_test')
   self.assertEqual(keys, actual)
 def test_find_keys(self):
   keys = ['key_1', 'key_2']
   self.expected_requests(
       [
         (
           'http://host:9001/get_matching_test_cases?name=my_test',
           {'retry_404': True},
           json.dumps(keys),
           None,
         ),
       ])
   actual = swarming.get_task_keys('http://host:9001', 'my_test')
   self.assertEqual(keys, actual)
 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_task_keys('http://host:9001', 'my_test')
   self.assertEqual(keys, actual)
Example #10
0
 def test_no_keys_on_first_attempt(self):
   self.mock(swarming.time, 'sleep', lambda x: x)
   keys = ['key_1', 'key_2']
   self.requests = [
     (
       '/get_matching_test_cases?name=my_test',
       {'retry_404': True},
       StringIO.StringIO('No matching Test Cases'),
     ),
     (
       '/get_matching_test_cases?name=my_test',
       {'retry_404': True},
       StringIO.StringIO(json.dumps(keys)),
     ),
   ]
   actual = swarming.get_task_keys('http://host:9001', 'my_test')
   self.assertEqual(keys, actual)
Example #11
0
def trigger_task(swarming_url, dimensions, 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(
    isolate_server='http://localhost:1',
    namespace='dummy-isolate',
    isolated_hash=1,
    task_name=name,
    shards=1,
    env={},
    dimensions=dimensions,
    working_dir=None,
    deadline=3600,
    verbose=False,
    profile=False,
    priority=100)
  # TODO(maruel): Make output size configurable.
  # TODO(maruel): Make number of shards configurable.
  output_size = 100
  cmd = ['python', '-c', 'print(\'1\'*%s)' % output_size]
  manifest.add_task('echo stuff', cmd)
  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': [
      {
        # Old API uses harcoded config name.
        'config_name': 'isolated',
        'num_instances': 1,
        'instance_index': 0,
      },
    ],
  }
  if result != expected:
    # New API doesn't have concept of config name so it uses the task name.
    expected['test_keys'][0]['config_name'] = name
    assert result == expected, '%s\n%s' % (result, expected)
  progress.update_item('%5d' % index, processing=1)
  try:
    logging.info('collect')
    test_keys = swarming.get_task_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, False, 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)
Example #12
0
def trigger_task(swarming_url, dimensions, sleep_time, output_size, 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(isolate_server='http://localhost:1',
                                 namespace='dummy-isolate',
                                 isolated_hash=1,
                                 task_name=name,
                                 extra_args=[],
                                 env={},
                                 dimensions=dimensions,
                                 deadline=int(timeout - TIMEOUT_OVERHEAD),
                                 verbose=False,
                                 profile=False,
                                 priority=100)
    cmd = [
        'python', '-c',
        'import time; print(\'1\'*%s); time.sleep(%d); print(\'Back\')' %
        (output_size, sleep_time)
    ]
    manifest.add_task('echo stuff', cmd)
    data = {'request': manifest.to_json()}
    response = net.url_read(swarming_url + '/test', data=data)
    if response is None:
        # Failed to trigger. Return a failure.
        return 'failed_trigger'

    result = json.loads(response)
    # Old API uses harcoded config name. New API doesn't have concept of config
    # name so it uses the task name. Ignore this detail.
    test_keys = []
    for key in result['test_keys']:
        key.pop('config_name')
        test_keys.append(key.pop('test_key'))
        assert re.match('[0-9a-f]+', test_keys[-1]), test_keys
    expected = {
        u'priority': 100,
        u'test_case_name': unicode(name),
        u'test_keys': [{
            u'num_instances': 1,
            u'instance_index': 0,
        }],
    }
    assert result == expected, '\n%s\n%s' % (result, expected)

    progress.update_item('%5d' % index, processing=1)
    try:
        logging.info('collect')
        new_test_keys = swarming.get_task_keys(swarming_url, name)
        if not new_test_keys:
            return 'no_test_keys'
        assert test_keys == new_test_keys, (test_keys, new_test_keys)
        out = [
            output for _index, output in swarming.yield_results(
                swarming_url, test_keys, timeout, None, False, None, False,
                True)
        ]
        if not out:
            return 'no_result'
        for item in out:
            item.pop('machine_tag')
            item.pop('machine_id')
            # TODO(maruel): Assert output even when run on a real bot.
            _out_actual = item.pop('output')
            # assert out_actual == swarming_load_test_bot.TASK_OUTPUT, out_actual
        expected = [{
            u'config_instance_index': 0,
            u'exit_codes': u'0',
            u'num_config_instances': 1,
        }]
        assert out == expected, '\n%s\n%s' % (out, expected)
        return time.time() - start
    finally:
        progress.update_item('%5d - done' % index, processing=-1, processed=1)
def trigger_task(swarming_url, dimensions, sleep_time, output_size, 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(
        isolate_server="http://localhost:1",
        namespace="dummy-isolate",
        isolated_hash=1,
        task_name=name,
        extra_args=[],
        env={},
        dimensions=dimensions,
        deadline=int(timeout - TIMEOUT_OVERHEAD),
        verbose=False,
        profile=False,
        priority=100,
    )
    cmd = ["python", "-c", "import time; print('1'*%s); time.sleep(%d); print('Back')" % (output_size, sleep_time)]
    manifest.add_task("echo stuff", cmd)
    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)
    # Old API uses harcoded config name. New API doesn't have concept of config
    # name so it uses the task name. Ignore this detail.
    test_keys = []
    for key in result["test_keys"]:
        key.pop("config_name")
        test_keys.append(key.pop("test_key"))
        assert re.match("[0-9a-f]+", test_keys[-1]), test_keys
    expected = {
        u"priority": 100,
        u"test_case_name": unicode(name),
        u"test_keys": [{u"num_instances": 1, u"instance_index": 0}],
    }
    assert result == expected, "\n%s\n%s" % (result, expected)

    progress.update_item("%5d" % index, processing=1)
    try:
        logging.info("collect")
        new_test_keys = swarming.get_task_keys(swarming_url, name)
        if not new_test_keys:
            return "no_test_keys"
        assert test_keys == new_test_keys, (test_keys, new_test_keys)
        out = [output for _index, output in swarming.yield_results(swarming_url, test_keys, timeout, None, False, None)]
        if not out:
            return "no_result"
        for item in out:
            item.pop("machine_tag")
            item.pop("machine_id")
            # TODO(maruel): Assert output even when run on a real bot.
            _out_actual = item.pop("output")
            # assert out_actual == swarming_load_test_bot.TASK_OUTPUT, out_actual
        expected = [{u"config_instance_index": 0, u"exit_codes": u"0", u"num_config_instances": 1}]
        assert out == expected, "\n%s\n%s" % (out, expected)
        return time.time() - start
    finally:
        progress.update_item("%5d - done" % index, processing=-1, processed=1)
def trigger_task(
    swarming_url, dimensions, sleep_time, output_size, 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(
    isolate_server='http://localhost:1',
    namespace='dummy-isolate',
    isolated_hash=1,
    task_name=name,
    extra_args=[],
    env={},
    dimensions=dimensions,
    working_dir=None,
    deadline=3600,
    verbose=False,
    profile=False,
    priority=100)
  cmd = [
    'python',
    '-c',
    'import time; print(\'1\'*%s); time.sleep(%d); print(\'Back\')' %
    (output_size, sleep_time)
  ]
  manifest.add_task('echo stuff', cmd)
  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)
  # Old API uses harcoded config name. New API doesn't have concept of config
  # name so it uses the task name. Ignore this detail.
  test_keys = []
  for key in result['test_keys']:
    key.pop('config_name')
    test_keys.append(key.pop('test_key'))
    assert re.match('[0-9a-f]+', test_keys[-1]), test_keys
  expected = {
    u'test_case_name': unicode(name),
    u'test_keys': [
      {
        u'num_instances': 1,
        u'instance_index': 0,
      }
    ],
  }
  assert result == expected, '\n%s\n%s' % (result, expected)

  progress.update_item('%5d' % index, processing=1)
  try:
    logging.info('collect')
    new_test_keys = swarming.get_task_keys(swarming_url, name)
    if not new_test_keys:
      return 'no_test_keys'
    assert test_keys == new_test_keys, (test_keys, new_test_keys)
    out = [
      output
      for _index, output in swarming.yield_results(
          swarming_url, test_keys, timeout, None, False, None)
    ]
    if not out:
      return 'no_result'
    for item in out:
      item.pop('machine_tag')
      item.pop('machine_id')
      # TODO(maruel): Assert output even when run on a real bot.
      _out_actual = item.pop('output')
      # assert out_actual == swarming_load_test_bot.TASK_OUTPUT, out_actual
    expected = [
      {
        u'config_instance_index': 0,
        u'exit_codes': u'0',
        u'num_config_instances': 1,
      }
    ]
    assert out == expected, '\n%s\n%s' % (out, expected)
    return time.time() - start
  finally:
    progress.update_item('%5d - done' % index, processing=-1, processed=1)
def trigger_task(swarming_url, dimensions, 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(isolate_server='http://localhost:1',
                                 namespace='dummy-isolate',
                                 isolated_hash=1,
                                 task_name=name,
                                 shards=1,
                                 env={},
                                 dimensions=dimensions,
                                 working_dir=None,
                                 deadline=3600,
                                 verbose=False,
                                 profile=False,
                                 priority=100)
    # TODO(maruel): Make output size configurable.
    # TODO(maruel): Make number of shards configurable.
    output_size = 100
    cmd = ['python', '-c', 'print(\'1\'*%s)' % output_size]
    manifest.add_task('echo stuff', cmd)
    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': [
            {
                # Old API uses harcoded config name.
                'config_name': 'isolated',
                'num_instances': 1,
                'instance_index': 0,
            },
        ],
    }
    if result != expected:
        # New API doesn't have concept of config name so it uses the task name.
        expected['test_keys'][0]['config_name'] = name
        assert result == expected, '%s\n%s' % (result, expected)
    progress.update_item('%5d' % index, processing=1)
    try:
        logging.info('collect')
        test_keys = swarming.get_task_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, False, 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)