Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: appengine/swarming/server/task_request_test.py

Issue 1939343002: swarming: change meaning of inputs_ref (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: nit Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The LUCI Authors. All rights reserved. 2 # Copyright 2014 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed by the Apache v2.0 license that can be 3 # Use of this source code is governed by the Apache v2.0 license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import datetime 6 import datetime
7 import logging 7 import logging
8 import os 8 import os
9 import random 9 import random
10 import sys 10 import sys
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 'dimensions': { 47 'dimensions': {
48 u'OS': u'Windows-3.1.1', 48 u'OS': u'Windows-3.1.1',
49 u'hostname': u'localhost', 49 u'hostname': u'localhost',
50 u'pool': u'default', 50 u'pool': u'default',
51 }, 51 },
52 'env': {u'foo': u'bar', u'joe': u'2'}, 52 'env': {u'foo': u'bar', u'joe': u'2'},
53 'execution_timeout_secs': 30, 53 'execution_timeout_secs': 30,
54 'grace_period_secs': 30, 54 'grace_period_secs': 30,
55 'idempotent': False, 55 'idempotent': False,
56 'io_timeout_secs': None, 56 'io_timeout_secs': None,
57 'outputs_target': task_request.IsolatedOutputsTarget(
58 isolatedserver='https://isolateserver.appspot.com',
59 namespace='default-gzip',
60 ),
57 } 61 }
58 props.update(properties) 62 props.update(properties)
59 now = utils.utcnow() 63 now = utils.utcnow()
60 args = { 64 args = {
61 'created_ts': now, 65 'created_ts': now,
62 'name': 'Request name', 66 'name': 'Request name',
63 'priority': 50, 67 'priority': 50,
64 'properties': task_request.TaskProperties(**props), 68 'properties': task_request.TaskProperties(**props),
65 'expiration_ts': now + datetime.timedelta(seconds=30), 69 'expiration_ts': now + datetime.timedelta(seconds=30),
66 'tags': [u'tag:1'], 70 'tags': [u'tag:1'],
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 u'hostname': u'localhost', 205 u'hostname': u'localhost',
202 u'pool': u'default', 206 u'pool': u'default',
203 }, 207 },
204 'env': {u'foo': u'bar', u'joe': u'2'}, 208 'env': {u'foo': u'bar', u'joe': u'2'},
205 'extra_args': [], 209 'extra_args': [],
206 'execution_timeout_secs': 30, 210 'execution_timeout_secs': 30,
207 'grace_period_secs': 30, 211 'grace_period_secs': 30,
208 'idempotent': True, 212 'idempotent': True,
209 'inputs_ref': None, 213 'inputs_ref': None,
210 'io_timeout_secs': None, 214 'io_timeout_secs': None,
215 'outputs_target': {
216 'isolatedserver': 'https://isolateserver.appspot.com',
217 'namespace': 'default-gzip',
218 },
211 'packages': [{'package_name': 'rm', 'version': PINNED_PACKAGE_VERSION}], 219 'packages': [{'package_name': 'rm', 'version': PINNED_PACKAGE_VERSION}],
212 } 220 }
213 expected_request = { 221 expected_request = {
214 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY, 222 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY,
215 'name': u'Request name', 223 'name': u'Request name',
216 'parent_task_id': unicode(parent_id), 224 'parent_task_id': unicode(parent_id),
217 'priority': 49, 225 'priority': 49,
218 'properties': expected_properties, 226 'properties': expected_properties,
219 # Intentionally hard code the hash value since it has to be deterministic. 227 # Intentionally hard code the hash value since it has to be deterministic.
220 # Other unit tests should use the calculated value. 228 # Other unit tests should use the calculated value.
221 'properties_hash': '83b350298f05eff6072d54d2c6f031d06cc30449', 229 'properties_hash': 'c145d80dcc95e0ff3b3160b7697f6136b81bc8bc',
222 'pubsub_topic': None, 230 'pubsub_topic': None,
223 'pubsub_userdata': None, 231 'pubsub_userdata': None,
224 'tags': [ 232 'tags': [
225 u'OS:Windows-3.1.1', 233 u'OS:Windows-3.1.1',
226 u'hostname:localhost', 234 u'hostname:localhost',
227 u'pool:default', 235 u'pool:default',
228 u'priority:49', 236 u'priority:49',
229 u'tag:1', 237 u'tag:1',
230 u'user:Jesus', 238 u'user:Jesus',
231 ], 239 ],
232 'user': u'Jesus', 240 'user': u'Jesus',
233 } 241 }
234 actual = request.to_dict() 242 actual = request.to_dict()
235 actual.pop('created_ts') 243 actual.pop('created_ts')
236 actual.pop('expiration_ts') 244 actual.pop('expiration_ts')
237 self.assertEqual(expected_request, actual) 245 self.assertEqual(expected_request, actual)
238 self.assertEqual(30, request.expiration_secs) 246 self.assertEqual(30, request.expiration_secs)
239 247
240 def test_make_request_isolated(self): 248 def test_make_request_isolated(self):
241 parent = mkreq(_gen_request(properties={ 249 parent = mkreq(_gen_request(properties={
242 'command': [], 250 'command': [],
243 'inputs_ref': { 251 'inputs_ref': {
244 'isolated': '0123456789012345678901234567890123456789', 252 'isolated': '0123456789012345678901234567890123456789',
245 'isolatedserver': 'http://localhost:1', 253 'isolatedserver': 'http://localhost:1',
246 'namespace': 'default-gzip', 254 'namespace': 'default-gzip',
247 }, 255 },
256 'outputs_target': None,
248 })) 257 }))
249 # Hack: Would need to know about TaskResultSummary. 258 # Hack: Would need to know about TaskResultSummary.
250 parent_id = task_pack.pack_request_key(parent.key) + '1' 259 parent_id = task_pack.pack_request_key(parent.key) + '1'
251 request = mkreq(_gen_request( 260 request = mkreq(_gen_request(
252 properties={'idempotent':True}, parent_task_id=parent_id)) 261 properties={'idempotent':True}, parent_task_id=parent_id))
253 expected_properties = { 262 expected_properties = {
254 'command': [u'command1', u'arg1'], 263 'command': [u'command1', u'arg1'],
255 'dimensions': { 264 'dimensions': {
256 u'OS': u'Windows-3.1.1', 265 u'OS': u'Windows-3.1.1',
257 u'hostname': u'localhost', 266 u'hostname': u'localhost',
258 u'pool': u'default', 267 u'pool': u'default',
259 }, 268 },
260 'env': {u'foo': u'bar', u'joe': u'2'}, 269 'env': {u'foo': u'bar', u'joe': u'2'},
261 'extra_args': [], 270 'extra_args': [],
262 'execution_timeout_secs': 30, 271 'execution_timeout_secs': 30,
263 'grace_period_secs': 30, 272 'grace_period_secs': 30,
264 'idempotent': True, 273 'idempotent': True,
265 'inputs_ref': None, 274 'inputs_ref': None,
266 'io_timeout_secs': None, 275 'io_timeout_secs': None,
276 'outputs_target': {
277 'isolatedserver': 'https://isolateserver.appspot.com',
278 'namespace': 'default-gzip',
279 },
267 'packages': [{'package_name': 'rm', 'version': PINNED_PACKAGE_VERSION}], 280 'packages': [{'package_name': 'rm', 'version': PINNED_PACKAGE_VERSION}],
268 } 281 }
269 expected_request = { 282 expected_request = {
270 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY, 283 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY,
271 'name': u'Request name', 284 'name': u'Request name',
272 'parent_task_id': unicode(parent_id), 285 'parent_task_id': unicode(parent_id),
273 'priority': 49, 286 'priority': 49,
274 'properties': expected_properties, 287 'properties': expected_properties,
275 # Intentionally hard code the hash value since it has to be deterministic. 288 # Intentionally hard code the hash value since it has to be deterministic.
276 # Other unit tests should use the calculated value. 289 # Other unit tests should use the calculated value.
277 'properties_hash': '83b350298f05eff6072d54d2c6f031d06cc30449', 290 'properties_hash': 'c145d80dcc95e0ff3b3160b7697f6136b81bc8bc',
278 'pubsub_topic': None, 291 'pubsub_topic': None,
279 'pubsub_userdata': None, 292 'pubsub_userdata': None,
280 'tags': [ 293 'tags': [
281 u'OS:Windows-3.1.1', 294 u'OS:Windows-3.1.1',
282 u'hostname:localhost', 295 u'hostname:localhost',
283 u'pool:default', 296 u'pool:default',
284 u'priority:49', 297 u'priority:49',
285 u'tag:1', 298 u'tag:1',
286 u'user:Jesus', 299 u'user:Jesus',
287 ], 300 ],
(...skipping 19 matching lines...) Expand all
307 _gen_request(parent_task_id='1d69b9f088008810') 320 _gen_request(parent_task_id='1d69b9f088008810')
308 321
309 def test_make_request_idempotent(self): 322 def test_make_request_idempotent(self):
310 request = mkreq(_gen_request(properties=dict(idempotent=True))) 323 request = mkreq(_gen_request(properties=dict(idempotent=True)))
311 as_dict = request.to_dict() 324 as_dict = request.to_dict()
312 self.assertEqual(True, as_dict['properties']['idempotent']) 325 self.assertEqual(True, as_dict['properties']['idempotent'])
313 # Intentionally hard code the hash value since it has to be deterministic. 326 # Intentionally hard code the hash value since it has to be deterministic.
314 # Other unit tests should use the calculated value. 327 # Other unit tests should use the calculated value.
315 # Ensure the algorithm is deterministic. 328 # Ensure the algorithm is deterministic.
316 self.assertEqual( 329 self.assertEqual(
317 '83b350298f05eff6072d54d2c6f031d06cc30449', as_dict['properties_hash']) 330 'c145d80dcc95e0ff3b3160b7697f6136b81bc8bc', as_dict['properties_hash'])
318 331
319 def test_duped(self): 332 def test_duped(self):
320 # Two TestRequest with the same properties. 333 # Two TestRequest with the same properties.
321 request_1 = mkreq(_gen_request(properties=dict(idempotent=True))) 334 request_1 = mkreq(_gen_request(properties=dict(idempotent=True)))
322 now = utils.utcnow() 335 now = utils.utcnow()
323 request_2 = mkreq(_gen_request( 336 request_2 = mkreq(_gen_request(
324 name='Other', 337 name='Other',
325 user='Other', 338 user='Other',
326 priority=201, 339 priority=201,
327 created_ts=now, 340 created_ts=now,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 now+datetime.timedelta(seconds=task_request._MIN_TIMEOUT_SECS))) 437 now+datetime.timedelta(seconds=task_request._MIN_TIMEOUT_SECS)))
425 mkreq(_gen_request( 438 mkreq(_gen_request(
426 created_ts=now, 439 created_ts=now,
427 expiration_ts= 440 expiration_ts=
428 now + datetime.timedelta(seconds=task_request._SEVEN_DAYS_SECS))) 441 now + datetime.timedelta(seconds=task_request._SEVEN_DAYS_SECS)))
429 442
430 # Try with isolated/isolatedserver/namespace. 443 # Try with isolated/isolatedserver/namespace.
431 with self.assertRaises(datastore_errors.BadValueError): 444 with self.assertRaises(datastore_errors.BadValueError):
432 mkreq(_gen_request(properties=dict( 445 mkreq(_gen_request(properties=dict(
433 command=['see', 'spot', 'run'], 446 command=['see', 'spot', 'run'],
434 inputs_ref=task_request.FilesRef()))) 447 inputs_ref=task_request.FilesRef(
448 isolated='deadbeef',
449 isolatedserver='http://localhost:1',
450 namespace='default-gzip'),
451 outputs_target=None)))
452 with self.assertRaises(datastore_errors.BadValueError):
453 mkreq(_gen_request(properties=dict(
454 inputs_ref=task_request.FilesRef(),
455 outputs_target=None)))
456 with self.assertRaises(datastore_errors.BadValueError):
457 mkreq(_gen_request(properties=dict(
458 inputs_ref=task_request.FilesRef(
459 isolated='deadbeef',
460 isolatedserver='http://localhost:1',
461 namespace='default-gzip'),
462 outputs_target=task_request.IsolatedOutputsTarget())))
463 with self.assertRaises(datastore_errors.BadValueError):
464 mkreq(_gen_request(properties=dict(
465 outputs_target=task_request.IsolatedOutputsTarget())))
466 mkreq(_gen_request(properties=dict(
467 command=[],
468 inputs_ref=task_request.FilesRef(
469 isolated='deadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
470 isolatedserver='http://localhost:1',
471 namespace='default-gzip'),
472 outputs_target=None)))
473 mkreq(_gen_request(properties=dict(
474 outputs_target=task_request.IsolatedOutputsTarget(
475 isolatedserver='https://isolateserver.appspot.com',
476 namespace='default-gzip'))))
477
435 478
436 def test_make_request_clone(self): 479 def test_make_request_clone(self):
437 # Compare with test_make_request(). 480 # Compare with test_make_request().
438 parent = mkreq(_gen_request()) 481 parent = mkreq(_gen_request())
439 # Hack: Would need to know about TaskResultSummary. 482 # Hack: Would need to know about TaskResultSummary.
440 parent_id = task_pack.pack_request_key(parent.key) + '1' 483 parent_id = task_pack.pack_request_key(parent.key) + '1'
441 data = _gen_request( 484 data = _gen_request(
442 properties=dict(idempotent=True), parent_task_id=parent_id) 485 properties=dict(idempotent=True), parent_task_id=parent_id)
443 request = task_request.make_request_clone(mkreq(data)) 486 request = task_request.make_request_clone(mkreq(data))
444 # Differences from make_request() are: 487 # Differences from make_request() are:
445 # - idempotent was reset to False. 488 # - idempotent was reset to False.
446 # - parent_task_id was reset to None. 489 # - parent_task_id was reset to None.
447 expected_properties = { 490 expected_properties = {
448 'command': [u'command1', u'arg1'], 491 'command': [u'command1', u'arg1'],
449 'dimensions': { 492 'dimensions': {
450 u'OS': u'Windows-3.1.1', 493 u'OS': u'Windows-3.1.1',
451 u'hostname': u'localhost', 494 u'hostname': u'localhost',
452 u'pool': u'default', 495 u'pool': u'default',
453 }, 496 },
454 'env': {u'foo': u'bar', u'joe': u'2'}, 497 'env': {u'foo': u'bar', u'joe': u'2'},
455 'execution_timeout_secs': 30, 498 'execution_timeout_secs': 30,
456 'extra_args': [], 499 'extra_args': [],
457 'grace_period_secs': 30, 500 'grace_period_secs': 30,
458 'idempotent': False, 501 'idempotent': False,
459 'inputs_ref': None, 502 'inputs_ref': None,
460 'io_timeout_secs': None, 503 'io_timeout_secs': None,
504 'outputs_target': {
505 'isolatedserver': 'https://isolateserver.appspot.com',
506 'namespace': 'default-gzip',
507 },
461 'packages': [{'package_name': 'rm', 'version': PINNED_PACKAGE_VERSION}], 508 'packages': [{'package_name': 'rm', 'version': PINNED_PACKAGE_VERSION}],
462 } 509 }
463 # Differences from make_request() are: 510 # Differences from make_request() are:
464 # - parent_task_id was reset to None. 511 # - parent_task_id was reset to None.
465 # - tag 'user:' was replaced 512 # - tag 'user:' was replaced
466 # - user was replaced. 513 # - user was replaced.
467 expected_request = { 514 expected_request = {
468 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY, 515 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY,
469 'name': u'Request name (Retry #1)', 516 'name': u'Request name (Retry #1)',
470 'parent_task_id': None, 517 'parent_task_id': None,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 ndb.Key(task_request.TaskRequest, 0x7f14acec2fcfffff), 573 ndb.Key(task_request.TaskRequest, 0x7f14acec2fcfffff),
527 task_request.request_id_to_key(0xeb5313d0300000)) 574 task_request.request_id_to_key(0xeb5313d0300000))
528 575
529 576
530 if __name__ == '__main__': 577 if __name__ == '__main__':
531 if '-v' in sys.argv: 578 if '-v' in sys.argv:
532 unittest.TestCase.maxDiff = None 579 unittest.TestCase.maxDiff = None
533 logging.basicConfig( 580 logging.basicConfig(
534 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) 581 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR)
535 unittest.main() 582 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698