| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import os | 6 import os |
| 7 import Queue | 7 import Queue |
| 8 import sys | 8 import sys |
| 9 import subprocess | 9 import subprocess |
| 10 import threading | 10 import threading |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 cmd = [sys.executable, os.path.join(TOOLS_DIR, 'run.py'), '--port=5555'] | 56 cmd = [sys.executable, os.path.join(TOOLS_DIR, 'run.py'), '--port=5555'] |
| 57 cmd.extend(args) | 57 cmd.extend(args) |
| 58 self.process = subprocess.Popen(cmd, stdout=subprocess.PIPE, | 58 self.process = subprocess.Popen(cmd, stdout=subprocess.PIPE, |
| 59 stderr=subprocess.PIPE) | 59 stderr=subprocess.PIPE) |
| 60 queue = Queue.Queue() | 60 queue = Queue.Queue() |
| 61 thread = threading.Thread(target=RunTest._SubprocessThread, | 61 thread = threading.Thread(target=RunTest._SubprocessThread, |
| 62 args=(self.process, queue)) | 62 args=(self.process, queue)) |
| 63 thread.daemon = True | 63 thread.daemon = True |
| 64 thread.start() | 64 thread.start() |
| 65 thread.join(timeout) | 65 thread.join(timeout) |
| 66 if not thread.is_alive(): | 66 self.assertFalse(thread.is_alive(), "Thread still running after timeout") |
| 67 returncode, stdout, stderr = queue.get(False) | |
| 68 return returncode, stdout, stderr | |
| 69 | 67 |
| 70 return -1, None, None | 68 returncode, stdout, stderr = queue.get(False) |
| 69 return returncode, stdout, stderr |
| 71 | 70 |
| 72 def _GetChromeMockArgs(self, page, http_request_type, sleep, | 71 |
| 72 @staticmethod |
| 73 def _GetChromeMockArgs(page, http_request_type, sleep, |
| 73 expect_to_be_killed=True): | 74 expect_to_be_killed=True): |
| 74 args = [] | 75 args = [] |
| 75 if page: | 76 if page: |
| 76 args.extend(['-P', page]) | 77 args.extend(['-P', page]) |
| 77 args.append('--') | 78 args.append('--') |
| 78 args.extend([sys.executable, os.path.join(SCRIPT_DIR, 'chrome_mock.py')]) | 79 args.extend([sys.executable, os.path.join(SCRIPT_DIR, 'chrome_mock.py')]) |
| 79 if http_request_type: | 80 if http_request_type: |
| 80 args.append('--' + http_request_type) | 81 args.append('--' + http_request_type) |
| 81 if sleep: | 82 if sleep: |
| 82 args.extend(['--sleep', str(sleep)]) | 83 args.extend(['--sleep', str(sleep)]) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 94 def testSubprocessDies(self): | 95 def testSubprocessDies(self): |
| 95 args = self._GetChromeMockArgs(page=None, http_request_type=None, sleep=0, | 96 args = self._GetChromeMockArgs(page=None, http_request_type=None, sleep=0, |
| 96 expect_to_be_killed=False) | 97 expect_to_be_killed=False) |
| 97 returncode, stdout, _ = self._Run(args, timeout=10) | 98 returncode, stdout, _ = self._Run(args, timeout=10) |
| 98 self.assertNotEqual(-1, returncode) | 99 self.assertNotEqual(-1, returncode) |
| 99 self.assertIn('Starting', stdout) | 100 self.assertIn('Starting', stdout) |
| 100 | 101 |
| 101 | 102 |
| 102 if __name__ == '__main__': | 103 if __name__ == '__main__': |
| 103 unittest.main() | 104 unittest.main() |
| OLD | NEW |