| OLD | NEW |
| 1 # Copyright (C) 2010 Google Inc. All rights reserved. | 1 # Copyright (C) 2010 Google Inc. All rights reserved. |
| 2 # Copyright (C) 2010 Gabor Rapcsanyi (rgabor@inf.u-szeged.hu), University of Sze
ged | 2 # Copyright (C) 2010 Gabor Rapcsanyi (rgabor@inf.u-szeged.hu), University of Sze
ged |
| 3 # | 3 # |
| 4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
| 6 # met: | 6 # met: |
| 7 # | 7 # |
| 8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 |
| 30 """Unit tests for manager.py.""" | 30 """Unit tests for manager.py.""" |
| 31 | 31 |
| 32 import optparse |
| 32 import time | 33 import time |
| 33 import unittest | 34 import unittest |
| 34 | 35 |
| 35 from webkitpy.common.host_mock import MockHost | 36 from webkitpy.common.host_mock import MockHost |
| 36 from webkitpy.layout_tests.controllers.manager import Manager | 37 from webkitpy.layout_tests.controllers.manager import Manager |
| 37 from webkitpy.layout_tests.models import test_expectations | 38 from webkitpy.layout_tests.models import test_expectations |
| 38 from webkitpy.layout_tests.models.test_run_results import TestRunResults | 39 from webkitpy.layout_tests.models.test_run_results import TestRunResults |
| 39 from webkitpy.tool.mock_tool import MockOptions | |
| 40 | 40 |
| 41 | 41 |
| 42 class FakePrinter(object): | 42 class FakePrinter(object): |
| 43 | 43 |
| 44 def write_update(self, s): | 44 def write_update(self, s): |
| 45 pass | 45 pass |
| 46 | 46 |
| 47 | 47 |
| 48 class ManagerTest(unittest.TestCase): | 48 class ManagerTest(unittest.TestCase): |
| 49 | 49 |
| 50 def test_needs_servers(self): | 50 def test_needs_servers(self): |
| 51 def get_manager(): | 51 def get_manager(): |
| 52 host = MockHost() | 52 host = MockHost() |
| 53 port = host.port_factory.get('test-mac-mac10.10') | 53 port = host.port_factory.get('test-mac-mac10.10') |
| 54 manager = Manager(port, options=MockOptions(http=True, max_locked_sh
ards=1), printer=FakePrinter()) | 54 manager = Manager(port, options=optparse.Values({'http': True, 'max_
locked_shards': 1}), printer=FakePrinter()) |
| 55 return manager | 55 return manager |
| 56 | 56 |
| 57 manager = get_manager() | 57 manager = get_manager() |
| 58 self.assertFalse(manager._needs_servers(['fast/html'])) | 58 self.assertFalse(manager._needs_servers(['fast/html'])) |
| 59 | 59 |
| 60 manager = get_manager() | 60 manager = get_manager() |
| 61 self.assertTrue(manager._needs_servers(['http/tests/misc'])) | 61 self.assertTrue(manager._needs_servers(['http/tests/misc'])) |
| 62 | 62 |
| 63 def test_servers_started(self): | 63 def test_servers_started(self): |
| 64 def get_manager(port): | 64 def get_manager(port): |
| 65 manager = Manager(port, options=MockOptions(http=True, max_locked_sh
ards=1), printer=FakePrinter()) | 65 manager = Manager(port, options=optparse.Values({'http': True, 'max_
locked_shards': 1}), printer=FakePrinter()) |
| 66 return manager | 66 return manager |
| 67 | 67 |
| 68 def start_http_server(additional_dirs, number_of_drivers): | 68 def start_http_server(additional_dirs, number_of_drivers): |
| 69 self.http_started = True | 69 self.http_started = True |
| 70 | 70 |
| 71 def start_websocket_server(): | 71 def start_websocket_server(): |
| 72 self.websocket_started = True | 72 self.websocket_started = True |
| 73 | 73 |
| 74 def stop_http_server(): | 74 def stop_http_server(): |
| 75 self.http_stopped = True | 75 self.http_stopped = True |
| (...skipping 30 matching lines...) Expand all Loading... |
| 106 self.assertEqual(self.http_started, False) | 106 self.assertEqual(self.http_started, False) |
| 107 self.assertEqual(self.websocket_started, False) | 107 self.assertEqual(self.websocket_started, False) |
| 108 manager._stop_servers() | 108 manager._stop_servers() |
| 109 self.assertEqual(self.http_stopped, False) | 109 self.assertEqual(self.http_stopped, False) |
| 110 self.assertEqual(self.websocket_stopped, False) | 110 self.assertEqual(self.websocket_stopped, False) |
| 111 | 111 |
| 112 def test_look_for_new_crash_logs(self): | 112 def test_look_for_new_crash_logs(self): |
| 113 def get_manager(): | 113 def get_manager(): |
| 114 host = MockHost() | 114 host = MockHost() |
| 115 port = host.port_factory.get('test-mac-mac10.10') | 115 port = host.port_factory.get('test-mac-mac10.10') |
| 116 manager = Manager(port, options=MockOptions(test_list=None, http=Tru
e, max_locked_shards=1), printer=FakePrinter()) | 116 manager = Manager( |
| 117 port, |
| 118 options=optparse.Values({'test_list': None, 'http': True, 'max_l
ocked_shards': 1}), |
| 119 printer=FakePrinter()) |
| 117 return manager | 120 return manager |
| 118 host = MockHost() | 121 host = MockHost() |
| 119 port = host.port_factory.get('test-mac-mac10.10') | 122 port = host.port_factory.get('test-mac-mac10.10') |
| 120 tests = ['failures/expected/crash.html'] | 123 tests = ['failures/expected/crash.html'] |
| 121 expectations = test_expectations.TestExpectations(port, tests) | 124 expectations = test_expectations.TestExpectations(port, tests) |
| 122 run_results = TestRunResults(expectations, len(tests)) | 125 run_results = TestRunResults(expectations, len(tests)) |
| 123 manager = get_manager() | 126 manager = get_manager() |
| 124 manager._look_for_new_crash_logs(run_results, time.time()) | 127 manager._look_for_new_crash_logs(run_results, time.time()) |
| 125 | 128 |
| 126 def _make_fake_test_result(self, host, results_directory): | 129 def _make_fake_test_result(self, host, results_directory): |
| 127 host.filesystem.maybe_make_directory(results_directory) | 130 host.filesystem.maybe_make_directory(results_directory) |
| 128 host.filesystem.write_binary_file(results_directory + '/results.html', '
This is a test results file') | 131 host.filesystem.write_binary_file(results_directory + '/results.html', '
This is a test results file') |
| 129 | 132 |
| 130 def test_rename_results_folder(self): | 133 def test_rename_results_folder(self): |
| 131 host = MockHost() | 134 host = MockHost() |
| 132 port = host.port_factory.get('test-mac-mac10.10') | 135 port = host.port_factory.get('test-mac-mac10.10') |
| 133 | 136 |
| 134 def get_manager(): | 137 def get_manager(): |
| 135 manager = Manager(port, options=MockOptions(max_locked_shards=1), pr
inter=FakePrinter()) | 138 manager = Manager(port, options=optparse.Values({'max_locked_shards'
: 1}), printer=FakePrinter()) |
| 136 return manager | 139 return manager |
| 137 self._make_fake_test_result(port.host, '/tmp/layout-test-results') | 140 self._make_fake_test_result(port.host, '/tmp/layout-test-results') |
| 138 self.assertTrue(port.host.filesystem.exists('/tmp/layout-test-results')) | 141 self.assertTrue(port.host.filesystem.exists('/tmp/layout-test-results')) |
| 139 timestamp = time.strftime( | 142 timestamp = time.strftime( |
| 140 "%Y-%m-%d-%H-%M-%S", time.localtime(port.host.filesystem.mtime('/tmp
/layout-test-results/results.html'))) | 143 "%Y-%m-%d-%H-%M-%S", time.localtime(port.host.filesystem.mtime('/tmp
/layout-test-results/results.html'))) |
| 141 archived_file_name = '/tmp/layout-test-results' + '_' + timestamp | 144 archived_file_name = '/tmp/layout-test-results' + '_' + timestamp |
| 142 manager = get_manager() | 145 manager = get_manager() |
| 143 manager._rename_results_folder() | 146 manager._rename_results_folder() |
| 144 self.assertFalse(port.host.filesystem.exists('/tmp/layout-test-results')
) | 147 self.assertFalse(port.host.filesystem.exists('/tmp/layout-test-results')
) |
| 145 self.assertTrue(port.host.filesystem.exists(archived_file_name)) | 148 self.assertTrue(port.host.filesystem.exists(archived_file_name)) |
| 146 | 149 |
| 147 def test_clobber_old_results(self): | 150 def test_clobber_old_results(self): |
| 148 host = MockHost() | 151 host = MockHost() |
| 149 port = host.port_factory.get('test-mac-mac10.10') | 152 port = host.port_factory.get('test-mac-mac10.10') |
| 150 | 153 |
| 151 def get_manager(): | 154 def get_manager(): |
| 152 manager = Manager(port, options=MockOptions(max_locked_shards=1), pr
inter=FakePrinter()) | 155 manager = Manager(port, options=optparse.Values({'max_locked_shards'
: 1}), printer=FakePrinter()) |
| 153 return manager | 156 return manager |
| 154 self._make_fake_test_result(port.host, '/tmp/layout-test-results') | 157 self._make_fake_test_result(port.host, '/tmp/layout-test-results') |
| 155 self.assertTrue(port.host.filesystem.exists('/tmp/layout-test-results')) | 158 self.assertTrue(port.host.filesystem.exists('/tmp/layout-test-results')) |
| 156 manager = get_manager() | 159 manager = get_manager() |
| 157 manager._clobber_old_results() | 160 manager._clobber_old_results() |
| 158 self.assertFalse(port.host.filesystem.exists('/tmp/layout-test-results')
) | 161 self.assertFalse(port.host.filesystem.exists('/tmp/layout-test-results')
) |
| 159 | 162 |
| 160 def test_limit_archived_results_count(self): | 163 def test_limit_archived_results_count(self): |
| 161 host = MockHost() | 164 host = MockHost() |
| 162 port = host.port_factory.get('test-mac-mac10.10') | 165 port = host.port_factory.get('test-mac-mac10.10') |
| 163 | 166 |
| 164 def get_manager(): | 167 def get_manager(): |
| 165 manager = Manager(port, options=MockOptions(max_locked_shards=1), pr
inter=FakePrinter()) | 168 manager = Manager(port, options=optparse.Values({'max_locked_shards'
: 1}), printer=FakePrinter()) |
| 166 return manager | 169 return manager |
| 167 for x in range(1, 31): | 170 for x in range(1, 31): |
| 168 dir_name = '/tmp/layout-test-results' + '_' + str(x) | 171 dir_name = '/tmp/layout-test-results' + '_' + str(x) |
| 169 self._make_fake_test_result(port.host, dir_name) | 172 self._make_fake_test_result(port.host, dir_name) |
| 170 manager = get_manager() | 173 manager = get_manager() |
| 171 manager._limit_archived_results_count() | 174 manager._limit_archived_results_count() |
| 172 deleted_dir_count = 0 | 175 deleted_dir_count = 0 |
| 173 for x in range(1, 31): | 176 for x in range(1, 31): |
| 174 dir_name = '/tmp/layout-test-results' + '_' + str(x) | 177 dir_name = '/tmp/layout-test-results' + '_' + str(x) |
| 175 if not port.host.filesystem.exists(dir_name): | 178 if not port.host.filesystem.exists(dir_name): |
| 176 deleted_dir_count = deleted_dir_count + 1 | 179 deleted_dir_count = deleted_dir_count + 1 |
| 177 self.assertEqual(deleted_dir_count, 5) | 180 self.assertEqual(deleted_dir_count, 5) |
| OLD | NEW |