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

Side by Side Diff: appengine/swarming/swarming_bot/bot_code/task_runner_test.py

Issue 2443663002: Pass args in file from task_runner to run_isolated (Closed)
Patch Set: Created 4 years, 2 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 # coding=utf-8 2 # coding=utf-8
3 # Copyright 2013 The LUCI Authors. All rights reserved. 3 # Copyright 2013 The LUCI Authors. All rights reserved.
4 # Use of this source code is governed under the Apache License, Version 2.0 4 # Use of this source code is governed under the Apache License, Version 2.0
5 # that can be found in the LICENSE file. 5 # that can be found in the LICENSE file.
6 6
7 import base64 7 import base64
8 import json 8 import json
9 import logging 9 import logging
10 import os 10 import os
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 u'namespace': u'default-gzip', 356 u'namespace': u'default-gzip',
357 }) 357 })
358 task_details = self.get_task_details(isolated={ 358 task_details = self.get_task_details(isolated={
359 'input': '123', 359 'input': '123',
360 'server': 'localhost:1', 360 'server': 'localhost:1',
361 'namespace': 'default-gzip', 361 'namespace': 'default-gzip',
362 }, extra_args=['foo', 'bar']) 362 }, extra_args=['foo', 'bar'])
363 # Mock running run_isolated with a script. 363 # Mock running run_isolated with a script.
364 SCRIPT_ISOLATED = ( 364 SCRIPT_ISOLATED = (
365 'import json, sys;\n' 365 'import json, sys;\n'
366 'if len(sys.argv) != 2:\n' 366 'args = []\n'
367 ' raise Exception(sys.argv);\n' 367 'if len(sys.argv) != 3 or sys.argv[1] != \'-f\':\n'
368 'with open(sys.argv[1], \'wb\') as f:\n' 368 ' raise Exception(sys.argv)\n'
369 'with open(sys.argv[2], \'r\') as argsfile:\n'
370 ' args = json.loads(argsfile.read())\n'
371 'if len(args) != 1:\n'
372 ' raise Exception(args);\n'
373 'with open(args[0], \'wb\') as f:\n'
369 ' json.dump({\n' 374 ' json.dump({\n'
370 ' \'exit_code\': 0,\n' 375 ' \'exit_code\': 0,\n'
371 ' \'had_hard_timeout\': False,\n' 376 ' \'had_hard_timeout\': False,\n'
372 ' \'internal_failure\': None,\n' 377 ' \'internal_failure\': None,\n'
373 ' \'outputs_ref\': {\n' 378 ' \'outputs_ref\': {\n'
374 ' \'isolated\': \'123\',\n' 379 ' \'isolated\': \'123\',\n'
375 ' \'isolatedserver\': \'http://localhost:1\',\n' 380 ' \'isolatedserver\': \'http://localhost:1\',\n'
376 ' \'namespace\': \'default-gzip\',\n' 381 ' \'namespace\': \'default-gzip\',\n'
377 ' },\n' 382 ' },\n'
378 ' }, f)\n' 383 ' }, f)\n'
379 'sys.stdout.write(\'hi\\n\')') 384 'sys.stdout.write(\'hi\\n\')')
380 self.mock( 385 self.mock(
381 task_runner, 'get_isolated_cmd', 386 task_runner, 'get_run_isolated',
387 lambda :
388 [sys.executable, '-u', '-c', SCRIPT_ISOLATED])
389 self.mock(
390 task_runner, 'get_isolated_args',
382 lambda _work_dir, _details, isolated_result, bot_file, min_free_space: 391 lambda _work_dir, _details, isolated_result, bot_file, min_free_space:
383 [sys.executable, '-u', '-c', SCRIPT_ISOLATED, isolated_result]) 392 [isolated_result])
384 expected = { 393 expected = {
385 u'exit_code': 0, 394 u'exit_code': 0,
386 u'hard_timeout': False, 395 u'hard_timeout': False,
387 u'io_timeout': False, 396 u'io_timeout': False,
388 u'must_signal_internal_failure': None, 397 u'must_signal_internal_failure': None,
389 u'version': task_runner.OUT_VERSION, 398 u'version': task_runner.OUT_VERSION,
390 } 399 }
391 self.assertEqual(expected, self._run_command(task_details)) 400 self.assertEqual(expected, self._run_command(task_details))
392 401
393 def test_run_command_fail(self): 402 def test_run_command_fail(self):
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 server.close() 1090 server.close()
1082 1091
1083 1092
1084 class TaskRunnerSmoke(unittest.TestCase): 1093 class TaskRunnerSmoke(unittest.TestCase):
1085 # Runs a real process and a real Swarming fake server. 1094 # Runs a real process and a real Swarming fake server.
1086 def setUp(self): 1095 def setUp(self):
1087 super(TaskRunnerSmoke, self).setUp() 1096 super(TaskRunnerSmoke, self).setUp()
1088 self.root_dir = tempfile.mkdtemp(prefix='task_runner') 1097 self.root_dir = tempfile.mkdtemp(prefix='task_runner')
1089 logging.info('Temp: %s', self.root_dir) 1098 logging.info('Temp: %s', self.root_dir)
1090 self._server = fake_swarming.Server(self) 1099 self._server = fake_swarming.Server(self)
1100 self.maxDiff = None
M-A Ruel 2016/10/21 20:15:20 Remove, you just have to pass -v on the command li
aludwin 2016/10/21 20:32:00 Yeesh. Would have been nice if someone said that o
1091 1101
1092 def tearDown(self): 1102 def tearDown(self):
1093 try: 1103 try:
1094 self._server.shutdown() 1104 self._server.shutdown()
1095 finally: 1105 finally:
1096 try: 1106 try:
1097 file_path.rmtree(self.root_dir) 1107 file_path.rmtree(self.root_dir)
1098 except OSError: 1108 except OSError:
1099 print >> sys.stderr, 'Failed to delete %s' % self.root_dir 1109 print >> sys.stderr, 'Failed to delete %s' % self.root_dir
1100 finally: 1110 finally:
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 fix_encoding.fix_encoding() 1204 fix_encoding.fix_encoding()
1195 if '-v' in sys.argv: 1205 if '-v' in sys.argv:
1196 unittest.TestCase.maxDiff = None 1206 unittest.TestCase.maxDiff = None
1197 logging_utils.prepare_logging(None) 1207 logging_utils.prepare_logging(None)
1198 logging_utils.set_console_level( 1208 logging_utils.set_console_level(
1199 logging.DEBUG if '-v' in sys.argv else logging.CRITICAL+1) 1209 logging.DEBUG if '-v' in sys.argv else logging.CRITICAL+1)
1200 # Fix litteral text expectation. 1210 # Fix litteral text expectation.
1201 os.environ['LANG'] = 'en_US.UTF-8' 1211 os.environ['LANG'] = 'en_US.UTF-8'
1202 os.environ['LANGUAGE'] = 'en_US.UTF-8' 1212 os.environ['LANGUAGE'] = 'en_US.UTF-8'
1203 unittest.main() 1213 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698