| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import base64 | 5 import base64 |
| 6 import contextlib | 6 import contextlib |
| 7 import datetime | 7 import datetime |
| 8 import json | 8 import json |
| 9 | 9 |
| 10 from components import auth | 10 from components import auth |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 def futuristic(result): | 27 def futuristic(result): |
| 28 f = ndb.Future() | 28 f = ndb.Future() |
| 29 f.set_result(result) | 29 f.set_result(result) |
| 30 return f | 30 return f |
| 31 | 31 |
| 32 | 32 |
| 33 class SwarmingTest(testing.AppengineTestCase): | 33 class SwarmingTest(testing.AppengineTestCase): |
| 34 def setUp(self): | 34 def setUp(self): |
| 35 super(SwarmingTest, self).setUp() | 35 super(SwarmingTest, self).setUp() |
| 36 self.mock(utils, 'utcnow', lambda: datetime.datetime(2015, 11, 30)) | 36 self.mock(utils, 'utcnow', lambda: datetime.datetime(2015, 11, 30)) |
| 37 bucket_cfg = project_config_pb2.Bucket( | 37 self.bucket_cfg = project_config_pb2.Bucket( |
| 38 name='bucket', | 38 name='bucket', |
| 39 swarming=project_config_pb2.Swarming( | 39 swarming=project_config_pb2.Swarming( |
| 40 hostname='chromium-swarm.appspot.com', | 40 hostname='chromium-swarm.appspot.com', |
| 41 url_format='https://example.com/{swarming_hostname}/{task_id}', | 41 url_format='https://example.com/{swarming_hostname}/{task_id}', |
| 42 common_swarming_tags=['commontag:yes'], | 42 common_swarming_tags=['commontag:yes'], |
| 43 common_dimensions=['cores:8', 'pool:default'], | 43 common_dimensions=['cores:8', 'pool:default'], |
| 44 common_recipe=project_config_pb2.Swarming.Recipe( | 44 common_recipe=project_config_pb2.Swarming.Recipe( |
| 45 repository='https://example.com/repo', | 45 repository='https://example.com/repo', |
| 46 name='recipe', | 46 name='recipe', |
| 47 ), | 47 ), |
| 48 builders=[ | 48 builders=[ |
| 49 project_config_pb2.Swarming.Builder( | 49 project_config_pb2.Swarming.Builder( |
| 50 name='builder', | 50 name='builder', |
| 51 swarming_tags=['buildertag:yes'], | 51 swarming_tags=['buildertag:yes'], |
| 52 dimensions=['os:Linux', 'pool:Chrome'], | 52 dimensions=['os:Linux', 'pool:Chrome'], |
| 53 recipe=project_config_pb2.Swarming.Recipe( | 53 recipe=project_config_pb2.Swarming.Recipe( |
| 54 properties=['predefined-property:x'], | 54 properties=['predefined-property:x'], |
| 55 ), | 55 ), |
| 56 priority=108, | 56 priority=108, |
| 57 ), | 57 ), |
| 58 ], | 58 ], |
| 59 ), | 59 ), |
| 60 ) | 60 ) |
| 61 self.mock(config, 'get_bucket_async', lambda name: futuristic(bucket_cfg)) | 61 self.mock( |
| 62 config, 'get_bucket_async', lambda name: futuristic(self.bucket_cfg)) |
| 62 | 63 |
| 63 task_template = { | 64 task_template = { |
| 64 'name': 'buildbucket-$bucket-$builder', | 65 'name': 'buildbucket-$bucket-$builder', |
| 65 'priority': '100', | 66 'priority': '100', |
| 66 'expiration_secs': '3600', | 67 'expiration_secs': '3600', |
| 67 'properties': { | 68 'properties': { |
| 68 'execution_timeout_secs': '3600', | 69 'execution_timeout_secs': '3600', |
| 69 'inputs_ref': { | 70 'inputs_ref': { |
| 70 'isolatedserver': 'https://isolateserver.appspot.com', | 71 'isolatedserver': 'https://isolateserver.appspot.com', |
| 71 'namespace': 'default-gzip', | 72 'namespace': 'default-gzip', |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 [], | 131 [], |
| 131 {'junk': 1}, | 132 {'junk': 1}, |
| 132 {'recipe': []}, | 133 {'recipe': []}, |
| 133 {'recipe': {'junk': 1}}, | 134 {'recipe': {'junk': 1}}, |
| 134 {'recipe': {'revision': 1}}, | 135 {'recipe': {'revision': 1}}, |
| 135 ] | 136 ] |
| 136 for p in bad: | 137 for p in bad: |
| 137 with self.assertRaises(errors.InvalidInputError): | 138 with self.assertRaises(errors.InvalidInputError): |
| 138 validate_swarming_param(p) | 139 validate_swarming_param(p) |
| 139 | 140 |
| 141 def test_execution_timeout(self): |
| 142 builder_cfg = project_config_pb2.Swarming.Builder( |
| 143 name='fast-builder', |
| 144 execution_timeout_secs=60, |
| 145 ) |
| 146 |
| 147 build = model.Build( |
| 148 bucket='bucket', |
| 149 parameters={ |
| 150 'builder_name': 'fast-builder', |
| 151 }, |
| 152 ) |
| 153 |
| 154 task_def = swarming.create_task_def_async( |
| 155 self.bucket_cfg.swarming, builder_cfg, build).get_result() |
| 156 |
| 157 self.assertEqual( |
| 158 task_def['properties']['execution_timeout_secs'], 60) |
| 159 |
| 140 def test_create_task_async(self): | 160 def test_create_task_async(self): |
| 141 build = model.Build( | 161 build = model.Build( |
| 142 bucket='bucket', | 162 bucket='bucket', |
| 143 tags=['builder:builder'], | 163 tags=['builder:builder'], |
| 144 parameters={ | 164 parameters={ |
| 145 'builder_name': 'builder', | 165 'builder_name': 'builder', |
| 146 'swarming': { | 166 'swarming': { |
| 147 'recipe': {'revision': 'badcoffee'}, | 167 'recipe': {'revision': 'badcoffee'}, |
| 148 }, | 168 }, |
| 149 'properties': { | 169 'properties': { |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 self.assertEqual(build.status, model.BuildStatus.COMPLETED) | 600 self.assertEqual(build.status, model.BuildStatus.COMPLETED) |
| 581 self.assertEqual(build.result, model.BuildResult.FAILURE) | 601 self.assertEqual(build.result, model.BuildResult.FAILURE) |
| 582 self.assertEqual(build.failure_reason, model.FailureReason.INFRA_FAILURE) | 602 self.assertEqual(build.failure_reason, model.FailureReason.INFRA_FAILURE) |
| 583 self.assertIsNotNone(build.result_details) | 603 self.assertIsNotNone(build.result_details) |
| 584 self.assertIsNone(build.lease_key) | 604 self.assertIsNone(build.lease_key) |
| 585 self.assertIsNotNone(build.complete_time) | 605 self.assertIsNotNone(build.complete_time) |
| 586 | 606 |
| 587 | 607 |
| 588 def b64json(data): | 608 def b64json(data): |
| 589 return base64.b64encode(json.dumps(data)) | 609 return base64.b64encode(json.dumps(data)) |
| OLD | NEW |