Chromium Code Reviews| Index: appengine/swarming/swarming_bot/bot_code/task_runner_test.py |
| diff --git a/appengine/swarming/swarming_bot/bot_code/task_runner_test.py b/appengine/swarming/swarming_bot/bot_code/task_runner_test.py |
| index f5ab36f069799da26e462b02b7e39085cc40577a..6e8c83799d1b57a7918fcd66f494afc2ed528038 100755 |
| --- a/appengine/swarming/swarming_bot/bot_code/task_runner_test.py |
| +++ b/appengine/swarming/swarming_bot/bot_code/task_runner_test.py |
| @@ -8,8 +8,8 @@ import base64 |
| import json |
| import logging |
| import os |
| +import re |
| import signal |
| -import shutil |
| import sys |
| import tempfile |
| import time |
| @@ -120,20 +120,24 @@ class TestTaskRunner(TestTaskRunnerBase): |
| super(TestTaskRunner, self).setUp() |
| self.mock(time, 'time', lambda: 1000000000.) |
| - def get_check_final(self, exit_code=0, output='hi\n', outputs_ref=None): |
| + def get_check_final(self, exit_code=0, output_re=r'^hi\n$', outputs_ref=None): |
| def check_final(kwargs): |
| - # It makes the diffing easier. |
| + # Ignore these values. |
| + kwargs['data'].pop('bot_overhead', None) |
| + kwargs['data'].pop('duration', None) |
| + |
| + output = '' |
| if 'output' in kwargs['data']: |
| - kwargs['data']['output'] = base64.b64decode(kwargs['data']['output']) |
| + output = base64.b64decode(kwargs['data'].pop('output')) |
| + self.assertTrue(re.match(output_re, output)) |
| + |
| expected = { |
| 'data': { |
| 'cost_usd': 10., |
| - 'duration': 0., |
| 'exit_code': exit_code, |
| 'hard_timeout': False, |
| 'id': 'localhost', |
| 'io_timeout': False, |
| - 'output': output, |
| 'output_chunk_start': 0, |
| 'task_id': 23, |
| }, |
| @@ -327,17 +331,14 @@ class TestTaskRunner(TestTaskRunnerBase): |
| self.assertEqual(expected, self._run_command(task_details)) |
| def test_run_command_os_error(self): |
| - # This runs the command for real. |
| - # OS specific error, fix expectation for other OSes. |
| - output = ( |
| - 'Command "executable_that_shouldnt_be_on_your_system ' |
| - 'thus_raising_OSError" failed to start.\n' |
| - 'Error: [Error 2] The system cannot find the file specified' |
| - ) if sys.platform == 'win32' else ( |
| - 'Command "executable_that_shouldnt_be_on_your_system ' |
| - 'thus_raising_OSError" failed to start.\n' |
| - 'Error: [Errno 2] No such file or directory') |
| - self.requests(cost_usd=10., exit_code=1, output=output) |
| + self.requests( |
| + cost_usd=10., |
| + exit_code=1, |
| + output_re=( |
| + # This is a beginning of run_isolate.py's output if binary is not |
| + # found. |
| + r'^<The executable does not exist or a dependent library is ' |
| + r'missing>')) |
| task_details = task_runner.TaskDetails( |
| { |
| 'bot_id': 'localhost', |
| @@ -367,7 +368,6 @@ class TestTaskRunner(TestTaskRunnerBase): |
| class Popen(object): |
| """Mocks the process so we can control how data is returned.""" |
| def __init__(self2, cmd, cwd, env, stdout, stderr, stdin, detached): |
| - self.assertEqual(task_details.command, cmd) |
|
nodir
2016/05/12 21:46:23
this test is not about checking command anyway
|
| self.assertEqual(self.work_dir, cwd) |
| expected_env = os.environ.copy() |
| expected_env['foo'] = 'bar' |
| @@ -567,16 +567,21 @@ class TestTaskRunnerNoTimeMock(TestTaskRunnerBase): |
| def get_check_final( |
| self, hard_timeout=False, io_timeout=False, exit_code=None, |
| - output='hi\n'): |
| + output_re='^hi\n$'): |
| def check_final(kwargs): |
| + kwargs['data'].pop('bot_overhead', None) |
| if hard_timeout or io_timeout: |
| self.assertLess(self.SHORT_TIME_OUT, kwargs['data'].pop('cost_usd')) |
| self.assertLess(self.SHORT_TIME_OUT, kwargs['data'].pop('duration')) |
| else: |
| self.assertLess(0., kwargs['data'].pop('cost_usd')) |
| self.assertLess(0., kwargs['data'].pop('duration')) |
| - # It makes the diffing easier. |
| - kwargs['data']['output'] = base64.b64decode(kwargs['data']['output']) |
| + |
| + output = '' |
| + if 'output' in kwargs['data']: |
| + output = base64.b64decode(kwargs['data'].pop('output')) |
| + self.assertTrue(re.match(output_re, output)) |
| + |
| self.assertEqual( |
| { |
| 'data': { |
| @@ -584,7 +589,6 @@ class TestTaskRunnerNoTimeMock(TestTaskRunnerBase): |
| 'hard_timeout': hard_timeout, |
| 'id': 'localhost', |
| 'io_timeout': io_timeout, |
| - 'output': output, |
| 'output_chunk_start': 0, |
| 'task_id': 23, |
| }, |
| @@ -622,7 +626,9 @@ class TestTaskRunnerNoTimeMock(TestTaskRunnerBase): |
| u'must_signal_internal_failure': None, |
| u'version': task_runner.OUT_VERSION, |
| } |
| - self.assertEqual(expected, self._run_command(task_details)) |
| + actual = self._run_command(task_details) |
| + actual.pop('bot_overhead', None) |
| + self.assertEqual(expected, actual) |
| def test_io(self): |
| # Actually 0xc000013a |
| @@ -643,7 +649,7 @@ class TestTaskRunnerNoTimeMock(TestTaskRunnerBase): |
| self.requests( |
| hard_timeout=True, |
| exit_code=0, |
| - output='hi\ngot signal %d\nbye\n' % task_runner.SIG_BREAK_OR_TERM) |
| + output_re='^hi\ngot signal %d\nbye\n$' % task_runner.SIG_BREAK_OR_TERM) |
| task_details = self.get_task_details( |
| self.SCRIPT_SIGNAL, hard_timeout=self.SHORT_TIME_OUT) |
| # Returns 0 because the process cleaned up itself. |
| @@ -659,7 +665,7 @@ class TestTaskRunnerNoTimeMock(TestTaskRunnerBase): |
| def test_io_signal(self): |
| self.requests( |
| io_timeout=True, exit_code=0, |
| - output='hi\ngot signal %d\nbye\n' % task_runner.SIG_BREAK_OR_TERM) |
| + output_re='^hi\ngot signal %d\nbye\n$' % task_runner.SIG_BREAK_OR_TERM) |
| task_details = self.get_task_details( |
| self.SCRIPT_SIGNAL, io_timeout=self.SHORT_TIME_OUT) |
| # Returns 0 because the process cleaned up itself. |
| @@ -708,7 +714,7 @@ class TestTaskRunnerNoTimeMock(TestTaskRunnerBase): |
| exit_code = 1 if sys.platform == 'win32' else -signal.SIGKILL |
| self.requests( |
| hard_timeout=True, exit_code=exit_code, |
| - output='hi\ngot signal %d\nbye\n' % task_runner.SIG_BREAK_OR_TERM) |
| + output_re='^hi\ngot signal %d\nbye\n$' % task_runner.SIG_BREAK_OR_TERM) |
| task_details = self.get_task_details( |
| self.SCRIPT_SIGNAL_HANG, hard_timeout=self.SHORT_TIME_OUT, |
| grace_period=self.SHORT_TIME_OUT) |
| @@ -726,7 +732,7 @@ class TestTaskRunnerNoTimeMock(TestTaskRunnerBase): |
| exit_code = 1 if sys.platform == 'win32' else -signal.SIGKILL |
| self.requests( |
| io_timeout=True, exit_code=exit_code, |
| - output='hi\ngot signal %d\nbye\n' % task_runner.SIG_BREAK_OR_TERM) |
| + output_re='^hi\ngot signal %d\nbye\n$' % task_runner.SIG_BREAK_OR_TERM) |
| task_details = self.get_task_details( |
| self.SCRIPT_SIGNAL_HANG, io_timeout=self.SHORT_TIME_OUT, |
| grace_period=self.SHORT_TIME_OUT) |
| @@ -1038,13 +1044,6 @@ class TaskRunnerSmoke(unittest.TestCase): |
| task_runner_log = os.path.join(self.root_dir, 'logs', 'task_runner.log') |
| with open(task_runner_log, 'rb') as f: |
| logging.info('task_runner.log:\n---\n%s---', f.read()) |
| - expected = { |
|
nodir
2016/05/12 21:46:23
wasn't used
|
| - u'exit_code': 0, |
| - u'hard_timeout': False, |
| - u'io_timeout': False, |
| - u'must_signal_internal_failure': None, |
| - u'version': task_runner.OUT_VERSION, |
| - } |
| self.assertEqual([], self._server.get_events()) |
| tasks = self._server.get_tasks() |
| for task in tasks.itervalues(): |
| @@ -1073,6 +1072,7 @@ class TaskRunnerSmoke(unittest.TestCase): |
| '4e019f31778ba7191f965469dc673280386bbd60-cacert.pem', |
| 'work', |
| 'logs', |
| + 'isolated', |
| # TODO(maruel): Move inside work. |
| 'task_runner_in.json', |
| 'task_runner_out.json', |