| OLD | NEW |
| 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 |
| 11 import re |
| 11 import signal | 12 import signal |
| 12 import shutil | |
| 13 import sys | 13 import sys |
| 14 import tempfile | 14 import tempfile |
| 15 import time | 15 import time |
| 16 import unittest | 16 import unittest |
| 17 | 17 |
| 18 import test_env_bot_code | 18 import test_env_bot_code |
| 19 test_env_bot_code.setup_test_env() | 19 test_env_bot_code.setup_test_env() |
| 20 | 20 |
| 21 # Creates a server mock for functions in net.py. | 21 # Creates a server mock for functions in net.py. |
| 22 import net_utils | 22 import net_utils |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 }, | 114 }, |
| 115 kwargs) | 115 kwargs) |
| 116 return check_first | 116 return check_first |
| 117 | 117 |
| 118 | 118 |
| 119 class TestTaskRunner(TestTaskRunnerBase): | 119 class TestTaskRunner(TestTaskRunnerBase): |
| 120 def setUp(self): | 120 def setUp(self): |
| 121 super(TestTaskRunner, self).setUp() | 121 super(TestTaskRunner, self).setUp() |
| 122 self.mock(time, 'time', lambda: 1000000000.) | 122 self.mock(time, 'time', lambda: 1000000000.) |
| 123 | 123 |
| 124 def get_check_final(self, exit_code=0, output='hi\n', outputs_ref=None): | 124 def get_check_final(self, exit_code=0, output_re=r'^hi\n$', outputs_ref=None): |
| 125 def check_final(kwargs): | 125 def check_final(kwargs): |
| 126 # It makes the diffing easier. | 126 # Ignore these values. |
| 127 kwargs['data'].pop('bot_overhead', None) |
| 128 kwargs['data'].pop('duration', None) |
| 129 |
| 130 output = '' |
| 127 if 'output' in kwargs['data']: | 131 if 'output' in kwargs['data']: |
| 128 kwargs['data']['output'] = base64.b64decode(kwargs['data']['output']) | 132 output = base64.b64decode(kwargs['data'].pop('output')) |
| 133 self.assertTrue(re.match(output_re, output)) |
| 134 |
| 129 expected = { | 135 expected = { |
| 130 'data': { | 136 'data': { |
| 131 'cost_usd': 10., | 137 'cost_usd': 10., |
| 132 'duration': 0., | |
| 133 'exit_code': exit_code, | 138 'exit_code': exit_code, |
| 134 'hard_timeout': False, | 139 'hard_timeout': False, |
| 135 'id': 'localhost', | 140 'id': 'localhost', |
| 136 'io_timeout': False, | 141 'io_timeout': False, |
| 137 'output': output, | |
| 138 'output_chunk_start': 0, | 142 'output_chunk_start': 0, |
| 139 'task_id': 23, | 143 'task_id': 23, |
| 140 }, | 144 }, |
| 141 } | 145 } |
| 142 if outputs_ref: | 146 if outputs_ref: |
| 143 expected['data']['outputs_ref'] = outputs_ref | 147 expected['data']['outputs_ref'] = outputs_ref |
| 144 self.assertEqual(expected, kwargs) | 148 self.assertEqual(expected, kwargs) |
| 145 return check_final | 149 return check_final |
| 146 | 150 |
| 147 def _run_command(self, task_details): | 151 def _run_command(self, task_details): |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 expected = { | 325 expected = { |
| 322 u'exit_code': 1, | 326 u'exit_code': 1, |
| 323 u'hard_timeout': False, | 327 u'hard_timeout': False, |
| 324 u'io_timeout': False, | 328 u'io_timeout': False, |
| 325 u'must_signal_internal_failure': None, | 329 u'must_signal_internal_failure': None, |
| 326 u'version': task_runner.OUT_VERSION, | 330 u'version': task_runner.OUT_VERSION, |
| 327 } | 331 } |
| 328 self.assertEqual(expected, self._run_command(task_details)) | 332 self.assertEqual(expected, self._run_command(task_details)) |
| 329 | 333 |
| 330 def test_run_command_os_error(self): | 334 def test_run_command_os_error(self): |
| 331 # This runs the command for real. | 335 self.requests( |
| 332 # OS specific error, fix expectation for other OSes. | 336 cost_usd=10., |
| 333 output = ( | 337 exit_code=1, |
| 334 'Command "executable_that_shouldnt_be_on_your_system ' | 338 output_re=( |
| 335 'thus_raising_OSError" failed to start.\n' | 339 # This is a beginning of run_isolate.py's output if binary is not |
| 336 'Error: [Error 2] The system cannot find the file specified' | 340 # found. |
| 337 ) if sys.platform == 'win32' else ( | 341 r'^<The executable does not exist or a dependent library is ' |
| 338 'Command "executable_that_shouldnt_be_on_your_system ' | 342 r'missing>')) |
| 339 'thus_raising_OSError" failed to start.\n' | |
| 340 'Error: [Errno 2] No such file or directory') | |
| 341 self.requests(cost_usd=10., exit_code=1, output=output) | |
| 342 task_details = task_runner.TaskDetails( | 343 task_details = task_runner.TaskDetails( |
| 343 { | 344 { |
| 344 'bot_id': 'localhost', | 345 'bot_id': 'localhost', |
| 345 'command': [ | 346 'command': [ |
| 346 'executable_that_shouldnt_be_on_your_system', | 347 'executable_that_shouldnt_be_on_your_system', |
| 347 'thus_raising_OSError', | 348 'thus_raising_OSError', |
| 348 ], | 349 ], |
| 349 'env': {}, | 350 'env': {}, |
| 350 'extra_args': [], | 351 'extra_args': [], |
| 351 'grace_period': 30., | 352 'grace_period': 30., |
| 352 'hard_timeout': 6, | 353 'hard_timeout': 6, |
| 353 'io_timeout': 6, | 354 'io_timeout': 6, |
| 354 'isolated': None, | 355 'isolated': None, |
| 355 'task_id': 23, | 356 'task_id': 23, |
| 356 }) | 357 }) |
| 357 expected = { | 358 expected = { |
| 358 u'exit_code': 1, | 359 u'exit_code': 1, |
| 359 u'hard_timeout': False, | 360 u'hard_timeout': False, |
| 360 u'io_timeout': False, | 361 u'io_timeout': False, |
| 361 u'must_signal_internal_failure': None, | 362 u'must_signal_internal_failure': None, |
| 362 u'version': task_runner.OUT_VERSION, | 363 u'version': task_runner.OUT_VERSION, |
| 363 } | 364 } |
| 364 self.assertEqual(expected, self._run_command(task_details)) | 365 self.assertEqual(expected, self._run_command(task_details)) |
| 365 | 366 |
| 366 def test_run_command_large(self): | 367 def test_run_command_large(self): |
| 367 # Method should have "self" as first argument - pylint: disable=E0213 | 368 # Method should have "self" as first argument - pylint: disable=E0213 |
| 368 class Popen(object): | 369 class Popen(object): |
| 369 """Mocks the process so we can control how data is returned.""" | 370 """Mocks the process so we can control how data is returned.""" |
| 370 def __init__(self2, cmd, cwd, env, stdout, stderr, stdin, detached): | 371 def __init__(self2, _cmd, cwd, env, stdout, stderr, stdin, detached): |
| 371 self.assertEqual(task_details.command, cmd) | |
| 372 self.assertEqual(self.work_dir, cwd) | 372 self.assertEqual(self.work_dir, cwd) |
| 373 expected_env = os.environ.copy() | 373 expected_env = os.environ.copy() |
| 374 expected_env['foo'] = 'bar' | 374 expected_env['foo'] = 'bar' |
| 375 self.assertEqual(expected_env, env) | 375 self.assertEqual(expected_env, env) |
| 376 self.assertEqual(subprocess42.PIPE, stdout) | 376 self.assertEqual(subprocess42.PIPE, stdout) |
| 377 self.assertEqual(subprocess42.STDOUT, stderr) | 377 self.assertEqual(subprocess42.STDOUT, stderr) |
| 378 self.assertEqual(subprocess42.PIPE, stdin) | 378 self.assertEqual(subprocess42.PIPE, stdin) |
| 379 self.assertEqual(True, detached) | 379 self.assertEqual(True, detached) |
| 380 self2._out = [ | 380 self2._out = [ |
| 381 'hi!\n', | 381 'hi!\n', |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 ' except IOError:\n' | 561 ' except IOError:\n' |
| 562 ' pass;\n' | 562 ' pass;\n' |
| 563 'print(\'bye\');\n' | 563 'print(\'bye\');\n' |
| 564 'time.sleep(100)') % ( | 564 'time.sleep(100)') % ( |
| 565 'signal.SIGBREAK' if sys.platform == 'win32' else 'signal.SIGTERM') | 565 'signal.SIGBREAK' if sys.platform == 'win32' else 'signal.SIGTERM') |
| 566 | 566 |
| 567 SCRIPT_HANG = 'import time; print(\'hi\'); time.sleep(100)' | 567 SCRIPT_HANG = 'import time; print(\'hi\'); time.sleep(100)' |
| 568 | 568 |
| 569 def get_check_final( | 569 def get_check_final( |
| 570 self, hard_timeout=False, io_timeout=False, exit_code=None, | 570 self, hard_timeout=False, io_timeout=False, exit_code=None, |
| 571 output='hi\n'): | 571 output_re='^hi\n$'): |
| 572 def check_final(kwargs): | 572 def check_final(kwargs): |
| 573 kwargs['data'].pop('bot_overhead', None) |
| 573 if hard_timeout or io_timeout: | 574 if hard_timeout or io_timeout: |
| 574 self.assertLess(self.SHORT_TIME_OUT, kwargs['data'].pop('cost_usd')) | 575 self.assertLess(self.SHORT_TIME_OUT, kwargs['data'].pop('cost_usd')) |
| 575 self.assertLess(self.SHORT_TIME_OUT, kwargs['data'].pop('duration')) | 576 self.assertLess(self.SHORT_TIME_OUT, kwargs['data'].pop('duration')) |
| 576 else: | 577 else: |
| 577 self.assertLess(0., kwargs['data'].pop('cost_usd')) | 578 self.assertLess(0., kwargs['data'].pop('cost_usd')) |
| 578 self.assertLess(0., kwargs['data'].pop('duration')) | 579 self.assertLess(0., kwargs['data'].pop('duration')) |
| 579 # It makes the diffing easier. | 580 |
| 580 kwargs['data']['output'] = base64.b64decode(kwargs['data']['output']) | 581 output = '' |
| 582 if 'output' in kwargs['data']: |
| 583 output = base64.b64decode(kwargs['data'].pop('output')) |
| 584 self.assertTrue(re.match(output_re, output)) |
| 585 |
| 581 self.assertEqual( | 586 self.assertEqual( |
| 582 { | 587 { |
| 583 'data': { | 588 'data': { |
| 584 'exit_code': exit_code, | 589 'exit_code': exit_code, |
| 585 'hard_timeout': hard_timeout, | 590 'hard_timeout': hard_timeout, |
| 586 'id': 'localhost', | 591 'id': 'localhost', |
| 587 'io_timeout': io_timeout, | 592 'io_timeout': io_timeout, |
| 588 'output': output, | |
| 589 'output_chunk_start': 0, | 593 'output_chunk_start': 0, |
| 590 'task_id': 23, | 594 'task_id': 23, |
| 591 }, | 595 }, |
| 592 }, | 596 }, |
| 593 kwargs) | 597 kwargs) |
| 594 return check_final | 598 return check_final |
| 595 | 599 |
| 596 def _load_and_run(self, manifest): | 600 def _load_and_run(self, manifest): |
| 597 # Dot not mock time since this test class is testing timeouts. | 601 # Dot not mock time since this test class is testing timeouts. |
| 598 server = 'https://localhost:1' | 602 server = 'https://localhost:1' |
| (...skipping 17 matching lines...) Expand all Loading... |
| 616 self.requests(hard_timeout=True, exit_code=sig) | 620 self.requests(hard_timeout=True, exit_code=sig) |
| 617 task_details = self.get_task_details( | 621 task_details = self.get_task_details( |
| 618 self.SCRIPT_HANG, hard_timeout=self.SHORT_TIME_OUT) | 622 self.SCRIPT_HANG, hard_timeout=self.SHORT_TIME_OUT) |
| 619 expected = { | 623 expected = { |
| 620 u'exit_code': sig, | 624 u'exit_code': sig, |
| 621 u'hard_timeout': True, | 625 u'hard_timeout': True, |
| 622 u'io_timeout': False, | 626 u'io_timeout': False, |
| 623 u'must_signal_internal_failure': None, | 627 u'must_signal_internal_failure': None, |
| 624 u'version': task_runner.OUT_VERSION, | 628 u'version': task_runner.OUT_VERSION, |
| 625 } | 629 } |
| 626 self.assertEqual(expected, self._run_command(task_details)) | 630 actual = self._run_command(task_details) |
| 631 actual.pop('bot_overhead', None) |
| 632 self.assertEqual(expected, actual) |
| 627 | 633 |
| 628 def test_io(self): | 634 def test_io(self): |
| 629 # Actually 0xc000013a | 635 # Actually 0xc000013a |
| 630 sig = -1073741510 if sys.platform == 'win32' else -signal.SIGTERM | 636 sig = -1073741510 if sys.platform == 'win32' else -signal.SIGTERM |
| 631 self.requests(io_timeout=True, exit_code=sig) | 637 self.requests(io_timeout=True, exit_code=sig) |
| 632 task_details = self.get_task_details( | 638 task_details = self.get_task_details( |
| 633 self.SCRIPT_HANG, io_timeout=self.SHORT_TIME_OUT) | 639 self.SCRIPT_HANG, io_timeout=self.SHORT_TIME_OUT) |
| 634 expected = { | 640 expected = { |
| 635 u'exit_code': sig, | 641 u'exit_code': sig, |
| 636 u'hard_timeout': False, | 642 u'hard_timeout': False, |
| 637 u'io_timeout': True, | 643 u'io_timeout': True, |
| 638 u'must_signal_internal_failure': None, | 644 u'must_signal_internal_failure': None, |
| 639 u'version': task_runner.OUT_VERSION, | 645 u'version': task_runner.OUT_VERSION, |
| 640 } | 646 } |
| 641 self.assertEqual(expected, self._run_command(task_details)) | 647 self.assertEqual(expected, self._run_command(task_details)) |
| 642 | 648 |
| 643 def test_hard_signal(self): | 649 def test_hard_signal(self): |
| 644 self.requests( | 650 self.requests( |
| 645 hard_timeout=True, | 651 hard_timeout=True, |
| 646 exit_code=0, | 652 exit_code=0, |
| 647 output='hi\ngot signal %d\nbye\n' % task_runner.SIG_BREAK_OR_TERM) | 653 output_re='^hi\ngot signal %d\nbye\n$' % task_runner.SIG_BREAK_OR_TERM) |
| 648 task_details = self.get_task_details( | 654 task_details = self.get_task_details( |
| 649 self.SCRIPT_SIGNAL, hard_timeout=self.SHORT_TIME_OUT) | 655 self.SCRIPT_SIGNAL, hard_timeout=self.SHORT_TIME_OUT) |
| 650 # Returns 0 because the process cleaned up itself. | 656 # Returns 0 because the process cleaned up itself. |
| 651 expected = { | 657 expected = { |
| 652 u'exit_code': 0, | 658 u'exit_code': 0, |
| 653 u'hard_timeout': True, | 659 u'hard_timeout': True, |
| 654 u'io_timeout': False, | 660 u'io_timeout': False, |
| 655 u'must_signal_internal_failure': None, | 661 u'must_signal_internal_failure': None, |
| 656 u'version': task_runner.OUT_VERSION, | 662 u'version': task_runner.OUT_VERSION, |
| 657 } | 663 } |
| 658 self.assertEqual(expected, self._run_command(task_details)) | 664 self.assertEqual(expected, self._run_command(task_details)) |
| 659 | 665 |
| 660 def test_io_signal(self): | 666 def test_io_signal(self): |
| 661 self.requests( | 667 self.requests( |
| 662 io_timeout=True, exit_code=0, | 668 io_timeout=True, exit_code=0, |
| 663 output='hi\ngot signal %d\nbye\n' % task_runner.SIG_BREAK_OR_TERM) | 669 output_re='^hi\ngot signal %d\nbye\n$' % task_runner.SIG_BREAK_OR_TERM) |
| 664 task_details = self.get_task_details( | 670 task_details = self.get_task_details( |
| 665 self.SCRIPT_SIGNAL, io_timeout=self.SHORT_TIME_OUT) | 671 self.SCRIPT_SIGNAL, io_timeout=self.SHORT_TIME_OUT) |
| 666 # Returns 0 because the process cleaned up itself. | 672 # Returns 0 because the process cleaned up itself. |
| 667 expected = { | 673 expected = { |
| 668 u'exit_code': 0, | 674 u'exit_code': 0, |
| 669 u'hard_timeout': False, | 675 u'hard_timeout': False, |
| 670 u'io_timeout': True, | 676 u'io_timeout': True, |
| 671 u'must_signal_internal_failure': None, | 677 u'must_signal_internal_failure': None, |
| 672 u'version': task_runner.OUT_VERSION, | 678 u'version': task_runner.OUT_VERSION, |
| 673 } | 679 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 702 u'io_timeout': True, | 708 u'io_timeout': True, |
| 703 u'must_signal_internal_failure': None, | 709 u'must_signal_internal_failure': None, |
| 704 u'version': task_runner.OUT_VERSION, | 710 u'version': task_runner.OUT_VERSION, |
| 705 } | 711 } |
| 706 self.assertEqual(expected, self._run_command(task_details)) | 712 self.assertEqual(expected, self._run_command(task_details)) |
| 707 | 713 |
| 708 def test_hard_signal_no_grace(self): | 714 def test_hard_signal_no_grace(self): |
| 709 exit_code = 1 if sys.platform == 'win32' else -signal.SIGKILL | 715 exit_code = 1 if sys.platform == 'win32' else -signal.SIGKILL |
| 710 self.requests( | 716 self.requests( |
| 711 hard_timeout=True, exit_code=exit_code, | 717 hard_timeout=True, exit_code=exit_code, |
| 712 output='hi\ngot signal %d\nbye\n' % task_runner.SIG_BREAK_OR_TERM) | 718 output_re='^hi\ngot signal %d\nbye\n$' % task_runner.SIG_BREAK_OR_TERM) |
| 713 task_details = self.get_task_details( | 719 task_details = self.get_task_details( |
| 714 self.SCRIPT_SIGNAL_HANG, hard_timeout=self.SHORT_TIME_OUT, | 720 self.SCRIPT_SIGNAL_HANG, hard_timeout=self.SHORT_TIME_OUT, |
| 715 grace_period=self.SHORT_TIME_OUT) | 721 grace_period=self.SHORT_TIME_OUT) |
| 716 # Returns 0 because the process cleaned up itself. | 722 # Returns 0 because the process cleaned up itself. |
| 717 expected = { | 723 expected = { |
| 718 u'exit_code': exit_code, | 724 u'exit_code': exit_code, |
| 719 u'hard_timeout': True, | 725 u'hard_timeout': True, |
| 720 u'io_timeout': False, | 726 u'io_timeout': False, |
| 721 u'must_signal_internal_failure': None, | 727 u'must_signal_internal_failure': None, |
| 722 u'version': task_runner.OUT_VERSION, | 728 u'version': task_runner.OUT_VERSION, |
| 723 } | 729 } |
| 724 self.assertEqual(expected, self._run_command(task_details)) | 730 self.assertEqual(expected, self._run_command(task_details)) |
| 725 | 731 |
| 726 def test_io_signal_no_grace(self): | 732 def test_io_signal_no_grace(self): |
| 727 exit_code = 1 if sys.platform == 'win32' else -signal.SIGKILL | 733 exit_code = 1 if sys.platform == 'win32' else -signal.SIGKILL |
| 728 self.requests( | 734 self.requests( |
| 729 io_timeout=True, exit_code=exit_code, | 735 io_timeout=True, exit_code=exit_code, |
| 730 output='hi\ngot signal %d\nbye\n' % task_runner.SIG_BREAK_OR_TERM) | 736 output_re='^hi\ngot signal %d\nbye\n$' % task_runner.SIG_BREAK_OR_TERM) |
| 731 task_details = self.get_task_details( | 737 task_details = self.get_task_details( |
| 732 self.SCRIPT_SIGNAL_HANG, io_timeout=self.SHORT_TIME_OUT, | 738 self.SCRIPT_SIGNAL_HANG, io_timeout=self.SHORT_TIME_OUT, |
| 733 grace_period=self.SHORT_TIME_OUT) | 739 grace_period=self.SHORT_TIME_OUT) |
| 734 # Returns 0 because the process cleaned up itself. | 740 # Returns 0 because the process cleaned up itself. |
| 735 expected = { | 741 expected = { |
| 736 u'exit_code': exit_code, | 742 u'exit_code': exit_code, |
| 737 u'hard_timeout': False, | 743 u'hard_timeout': False, |
| 738 u'io_timeout': True, | 744 u'io_timeout': True, |
| 739 u'must_signal_internal_failure': None, | 745 u'must_signal_internal_failure': None, |
| 740 u'version': task_runner.OUT_VERSION, | 746 u'version': task_runner.OUT_VERSION, |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 while os.path.isfile(signal_file): | 1038 while os.path.isfile(signal_file): |
| 1033 time.sleep(0.01) | 1039 time.sleep(0.01) |
| 1034 # Send SIGTERM to task_runner itself. Ensure the right thing happen. | 1040 # Send SIGTERM to task_runner itself. Ensure the right thing happen. |
| 1035 # Note that on Windows, this is actually sending a SIGBREAK since there's no | 1041 # Note that on Windows, this is actually sending a SIGBREAK since there's no |
| 1036 # such thing as SIGTERM. | 1042 # such thing as SIGTERM. |
| 1037 proc.send_signal(signal.SIGTERM) | 1043 proc.send_signal(signal.SIGTERM) |
| 1038 proc.wait() | 1044 proc.wait() |
| 1039 task_runner_log = os.path.join(self.root_dir, 'logs', 'task_runner.log') | 1045 task_runner_log = os.path.join(self.root_dir, 'logs', 'task_runner.log') |
| 1040 with open(task_runner_log, 'rb') as f: | 1046 with open(task_runner_log, 'rb') as f: |
| 1041 logging.info('task_runner.log:\n---\n%s---', f.read()) | 1047 logging.info('task_runner.log:\n---\n%s---', f.read()) |
| 1042 expected = { | |
| 1043 u'exit_code': 0, | |
| 1044 u'hard_timeout': False, | |
| 1045 u'io_timeout': False, | |
| 1046 u'must_signal_internal_failure': None, | |
| 1047 u'version': task_runner.OUT_VERSION, | |
| 1048 } | |
| 1049 self.assertEqual([], self._server.get_events()) | 1048 self.assertEqual([], self._server.get_events()) |
| 1050 tasks = self._server.get_tasks() | 1049 tasks = self._server.get_tasks() |
| 1051 for task in tasks.itervalues(): | 1050 for task in tasks.itervalues(): |
| 1052 for event in task: | 1051 for event in task: |
| 1053 event.pop('cost_usd') | 1052 event.pop('cost_usd') |
| 1054 event.pop('duration', None) | 1053 event.pop('duration', None) |
| 1055 event.pop('bot_overhead', None) | 1054 event.pop('bot_overhead', None) |
| 1056 expected = { | 1055 expected = { |
| 1057 '23': [ | 1056 '23': [ |
| 1058 { | 1057 { |
| 1059 u'id': u'localhost', | 1058 u'id': u'localhost', |
| 1060 u'task_id': 23, | 1059 u'task_id': 23, |
| 1061 }, | 1060 }, |
| 1062 { | 1061 { |
| 1063 u'exit_code': exit_code, | 1062 u'exit_code': exit_code, |
| 1064 u'hard_timeout': False, | 1063 u'hard_timeout': False, |
| 1065 u'id': u'localhost', | 1064 u'id': u'localhost', |
| 1066 u'io_timeout': False, | 1065 u'io_timeout': False, |
| 1067 u'task_id': 23, | 1066 u'task_id': 23, |
| 1068 }, | 1067 }, |
| 1069 ], | 1068 ], |
| 1070 } | 1069 } |
| 1071 self.assertEqual(expected, tasks) | 1070 self.assertEqual(expected, tasks) |
| 1072 expected = { | 1071 expected = { |
| 1073 'swarming_bot.1.zip', | 1072 'swarming_bot.1.zip', |
| 1074 '4e019f31778ba7191f965469dc673280386bbd60-cacert.pem', | 1073 '4e019f31778ba7191f965469dc673280386bbd60-cacert.pem', |
| 1075 'work', | 1074 'work', |
| 1076 'logs', | 1075 'logs', |
| 1076 'isolated', |
| 1077 # TODO(maruel): Move inside work. | 1077 # TODO(maruel): Move inside work. |
| 1078 'task_runner_in.json', | 1078 'task_runner_in.json', |
| 1079 'task_runner_out.json', | 1079 'task_runner_out.json', |
| 1080 } | 1080 } |
| 1081 self.assertEqual(expected, set(os.listdir(self.root_dir))) | 1081 self.assertEqual(expected, set(os.listdir(self.root_dir))) |
| 1082 expected = { | 1082 expected = { |
| 1083 u'exit_code': exit_code, | 1083 u'exit_code': exit_code, |
| 1084 u'hard_timeout': False, | 1084 u'hard_timeout': False, |
| 1085 u'io_timeout': False, | 1085 u'io_timeout': False, |
| 1086 u'must_signal_internal_failure': | 1086 u'must_signal_internal_failure': |
| 1087 u'task_runner received signal %d' % task_runner.SIG_BREAK_OR_TERM, | 1087 u'task_runner received signal %d' % task_runner.SIG_BREAK_OR_TERM, |
| 1088 u'version': 3, | 1088 u'version': 3, |
| 1089 } | 1089 } |
| 1090 with open(task_result_file, 'rb') as f: | 1090 with open(task_result_file, 'rb') as f: |
| 1091 self.assertEqual(expected, json.load(f)) | 1091 self.assertEqual(expected, json.load(f)) |
| 1092 self.assertEqual(0, proc.returncode) | 1092 self.assertEqual(0, proc.returncode) |
| 1093 | 1093 |
| 1094 | 1094 |
| 1095 if __name__ == '__main__': | 1095 if __name__ == '__main__': |
| 1096 fix_encoding.fix_encoding() | 1096 fix_encoding.fix_encoding() |
| 1097 if '-v' in sys.argv: | 1097 if '-v' in sys.argv: |
| 1098 unittest.TestCase.maxDiff = None | 1098 unittest.TestCase.maxDiff = None |
| 1099 logging_utils.prepare_logging(None) | 1099 logging_utils.prepare_logging(None) |
| 1100 logging_utils.set_console_level( | 1100 logging_utils.set_console_level( |
| 1101 logging.DEBUG if '-v' in sys.argv else logging.CRITICAL+1) | 1101 logging.DEBUG if '-v' in sys.argv else logging.CRITICAL+1) |
| 1102 # Fix litteral text expectation. | 1102 # Fix litteral text expectation. |
| 1103 os.environ['LANG'] = 'en_US.UTF-8' | 1103 os.environ['LANG'] = 'en_US.UTF-8' |
| 1104 os.environ['LANGUAGE'] = 'en_US.UTF-8' | 1104 os.environ['LANGUAGE'] = 'en_US.UTF-8' |
| 1105 unittest.main() | 1105 unittest.main() |
| OLD | NEW |