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)
Example #2
0
    def test_basic_linux(self):
        """A basic linux manifest test to ensure that windows specific values
       aren't used.
    """
        manifest = swarming.Manifest(isolated_hash=FILE_HASH,
                                     test_name=TEST_NAME,
                                     shards=1,
                                     test_filter='*',
                                     slave_os='Linux',
                                     working_dir='swarm_tests',
                                     isolate_server='http://localhost:8081',
                                     verbose=False,
                                     profile=False,
                                     priority=101,
                                     algo=ALGO)

        swarming.chromium_setup(manifest)
        manifest_json = json.loads(manifest.to_json())

        expected = generate_expected_json(
            shards=1,
            slave_os='linux2',
            working_dir='swarm_tests',
            isolate_server=u'http://localhost:8081',
            profile=False)
        self.assertEqual(expected, manifest_json)
Example #3
0
  def test_manifest_for_shard(self):
    manifest = swarming.Manifest(
        isolate_server='http://localhost:8081',
        namespace='default-gzip',
        isolated_hash=FILE_HASH,
        task_name=TEST_NAME,
        extra_args=None,
        env=swarming.setup_googletest({}, 5, 3),
        dimensions={'os': 'Linux'},
        deadline=60*60,
        verbose=False,
        profile=False,
        priority=101)

    swarming.setup_run_isolated(manifest, None)
    manifest_json = json.loads(manifest.to_json())

    expected = generate_expected_json(
        shards=5,
        shard_index=3,
        dimensions={u'os': u'Linux'},
        env={},
        isolate_server=u'http://localhost:8081',
        profile=False)
    self.assertEqual(expected, manifest_json)
Example #4
0
  def test_manifest_with_extra_args(self):
    manifest = swarming.Manifest(
        isolate_server='http://localhost:8081',
        namespace='default-gzip',
        isolated_hash=FILE_HASH,
        task_name=TEST_NAME,
        extra_args=['--extra-cmd-arg=1234', 'some more'],
        env={},
        dimensions={'os': 'Windows'},
        deadline=60*60,
        verbose=False,
        profile=False,
        priority=101)

    swarming.setup_run_isolated(manifest, None)
    manifest_json = json.loads(manifest.to_json())

    expected = generate_expected_json(
        shards=1,
        shard_index=0,
        dimensions={u'os': u'Windows'},
        env={},
        isolate_server=u'http://localhost:8081',
        profile=False,
        extra_args=['--extra-cmd-arg=1234', 'some more'])
    self.assertEqual(expected, manifest_json)
Example #5
0
  def test_zip_bundle_files(self):
    manifest = swarming.Manifest(
        isolate_server='http://localhost:8081',
        namespace='default-gzip',
        isolated_hash=FILE_HASH,
        task_name=TEST_NAME,
        extra_args=None,
        env={},
        dimensions={'os': 'Linux'},
        deadline=60*60,
        verbose=False,
        profile=False,
        priority=101)

    bundle = zip_package.ZipPackage(swarming.ROOT_DIR)
    swarming.setup_run_isolated(manifest, bundle)

    self.assertEqual(
        set(['run_isolated.zip', 'swarm_cleanup.py']), set(bundle.files))
Example #6
0
    def test_basic_manifest(self):
        manifest = swarming.Manifest(isolated_hash=FILE_HASH,
                                     test_name=TEST_NAME,
                                     shards=2,
                                     test_filter='*',
                                     slave_os='Windows',
                                     working_dir='swarm_tests',
                                     isolate_server='http://localhost:8081',
                                     verbose=False,
                                     profile=False,
                                     priority=101,
                                     algo=ALGO)

        swarming.chromium_setup(manifest)
        manifest_json = json.loads(manifest.to_json())

        expected = generate_expected_json(
            shards=2,
            slave_os='win32',
            working_dir='swarm_tests',
            isolate_server=u'http://localhost:8081',
            profile=False)
        self.assertEqual(expected, manifest_json)
Example #7
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, 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)