def test_trigger_task_shards_2_shards(self): task_request = swarming.TaskRequest( command=["a", "b"], data=[], dimensions={"foo": "bar", "os": "Mac"}, env={}, expiration=60 * 60, hard_timeout=60, idempotent=False, io_timeout=60, name=TEST_NAME, priority=101, tags=["taga", "tagb"], user="******", verbose=False, ) request_1 = swarming.task_request_to_raw_request(task_request) request_1["name"] = u"unit_tests:0:2" request_1["properties"]["env"] = {"GTEST_SHARD_INDEX": "0", "GTEST_TOTAL_SHARDS": "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"] = {"GTEST_SHARD_INDEX": "1", "GTEST_TOTAL_SHARDS": "2"} result_2 = gen_request_response(request_2, task_id="12400") self.expected_requests( [ ( "https://localhost:1/swarming/api/v1/client/handshake", {"data": {}, "headers": {"X-XSRF-Token-Request": "1"}}, {"server_version": "v1", "xsrf_token": "Token"}, ), ( "https://localhost:1/swarming/api/v1/client/request", {"data": request_1, "headers": {"X-XSRF-Token": "Token"}}, result_1, ), ( "https://localhost:1/swarming/api/v1/client/request", {"data": request_2, "headers": {"X-XSRF-Token": "Token"}}, 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)
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( 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_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/_ah/api/swarming/v1/tasks/new", {"data": request_1}, result_1), ("https://localhost:1/_ah/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)
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')
def test_trigger_task_shards_priority_override(self): task_request = swarming.TaskRequest( command=["a", "b"], data=[["https://foo.invalid/bar", "bar.zip"]], dimensions={"foo": "bar", "os": "Mac"}, env={}, expiration=60 * 60, hard_timeout=60, idempotent=False, io_timeout=60, name=TEST_NAME, priority=101, tags=["taga", "tagb"], user="******", verbose=False, ) os.environ["SWARMING_TASK_ID"] = "123" try: request = swarming.task_request_to_raw_request(task_request) finally: os.environ.pop("SWARMING_TASK_ID") self.assertEqual("123", request["parent_task_id"]) result = gen_request_response(request) result["request"]["priority"] = 200 self.expected_requests( [ ( "https://localhost:1/swarming/api/v1/client/handshake", {"data": {}, "headers": {"X-XSRF-Token-Request": "1"}}, {"server_version": "v1", "xsrf_token": "Token"}, ), ( "https://localhost:1/swarming/api/v1/client/request", {"data": request, "headers": {"X-XSRF-Token": "Token"}}, 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")
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')
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")
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( 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_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/_ah/api/swarming/v1/tasks/new', {'data': request_1}, result_1, ), ( 'https://localhost:1/_ah/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)
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)