예제 #1
0
    def test_trigger_task_shards_priority_override(self):
        task_request = swarming.NewTaskRequest(
            expiration_secs=60 * 60,
            name=TEST_NAME,
            parent_task_id='123',
            priority=101,
            properties=swarming.TaskProperties(command=['a', 'b'],
                                               dimensions={
                                                   'foo': 'bar',
                                                   'os': 'Mac'
                                               },
                                               env={},
                                               execution_timeout_secs=60,
                                               extra_args=[],
                                               grace_period_secs=30,
                                               idempotent=False,
                                               inputs_ref=None,
                                               io_timeout_secs=60),
            tags=['taga', 'tagb'],
            user='******')

        request = swarming.task_request_to_raw_request(task_request)
        self.assertEqual('123', request['parent_task_id'])

        result = gen_request_response(request)
        result['request']['priority'] = 200
        self.expected_requests([
            (
                'https://localhost:1/_ah/api/swarming/v1/tasks/new',
                {
                    'data': request
                },
                result,
            ),
        ])

        os.environ['SWARMING_TASK_ID'] = '123'
        try:
            tasks = swarming.trigger_task_shards(
                swarming='https://localhost:1',
                shards=1,
                task_request=task_request)
        finally:
            os.environ.pop('SWARMING_TASK_ID')
        expected = {
            u'unit_tests': {
                'shard_index': 0,
                'task_id': '12300',
                'view_url': 'https://localhost:1/user/task/12300',
            }
        }
        self.assertEqual(expected, tasks)
        self._check_output('', 'Priority was reset to 200\n')
예제 #2
0
  def test_trigger_task_shards_2_shards(self):
    task_request = swarming.NewTaskRequest(
        expiration_secs=60*60,
        name=TEST_NAME,
        parent_task_id=None,
        priority=101,
        properties=swarming.TaskProperties(
            cipd_input=None,
            command=['a', 'b'],
            dimensions={'foo': 'bar', 'os': 'Mac'},
            env={},
            execution_timeout_secs=60,
            extra_args=[],
            grace_period_secs=30,
            idempotent=False,
            inputs_ref=None,
            io_timeout_secs=60),
        tags=['tag:a', 'tag:b'],
        user='******')

    request_1 = swarming.task_request_to_raw_request(task_request)
    request_1['name'] = u'unit_tests:0:2'
    request_1['properties']['env'] = [
      {'key': 'GTEST_SHARD_INDEX', 'value': '0'},
      {'key': 'GTEST_TOTAL_SHARDS', 'value': '2'},
    ]
    result_1 = gen_request_response(request_1)

    request_2 = swarming.task_request_to_raw_request(task_request)
    request_2['name'] = u'unit_tests:1:2'
    request_2['properties']['env'] = [
      {'key': 'GTEST_SHARD_INDEX', 'value': '1'},
      {'key': 'GTEST_TOTAL_SHARDS', 'value': '2'},
    ]
    result_2 = gen_request_response(request_2, task_id='12400')
    self.expected_requests(
        [
          (
            'https://localhost:1/api/swarming/v1/tasks/new',
            {'data': request_1},
            result_1,
          ),
          (
            'https://localhost:1/api/swarming/v1/tasks/new',
            {'data': request_2},
            result_2,
          ),
        ])

    tasks = swarming.trigger_task_shards(
        swarming='https://localhost:1',
        task_request=task_request,
        shards=2)
    expected = {
      u'unit_tests:0:2': {
        'shard_index': 0,
        'task_id': '12300',
        'view_url': 'https://localhost:1/user/task/12300',
      },
      u'unit_tests:1:2': {
        'shard_index': 1,
        'task_id': '12400',
        'view_url': 'https://localhost:1/user/task/12400',
      },
    }
    self.assertEqual(expected, tasks)