Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import json | 5 import json |
| 6 import mock | 6 import mock |
| 7 import os | 7 import os |
| 8 import tempfile | 8 import tempfile |
| 9 import unittest | 9 import unittest |
| 10 | 10 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 return expectations | 71 return expectations |
| 72 | 72 |
| 73 @classmethod | 73 @classmethod |
| 74 def StartBrowser(cls): | 74 def StartBrowser(cls): |
| 75 super(SimpleIntegrationUnittest, cls).StartBrowser() | 75 super(SimpleIntegrationUnittest, cls).StartBrowser() |
| 76 cls._num_browser_starts += 1 | 76 cls._num_browser_starts += 1 |
| 77 | 77 |
| 78 def RunActualGpuTest(self, file_path, *args): | 78 def RunActualGpuTest(self, file_path, *args): |
| 79 if file_path == 'failure.html': | 79 if file_path == 'failure.html': |
| 80 self.fail('Expected failure') | 80 self.fail('Expected failure') |
| 81 elif file_path == 'restart.html': | |
| 82 try: | |
| 83 # This will fail because the browser is already started | |
| 84 self.StartBrowser() | |
| 85 finally: | |
| 86 self.StopBrowser() | |
| 87 elif file_path == 'flaky.html': | 81 elif file_path == 'flaky.html': |
| 88 if self.__class__._num_flaky_runs_to_fail > 0: | 82 if self.__class__._num_flaky_runs_to_fail > 0: |
| 89 self.__class__._num_flaky_runs_to_fail -= 1 | 83 self.__class__._num_flaky_runs_to_fail -= 1 |
| 90 self.fail('Expected flaky failure') | 84 self.fail('Expected flaky failure') |
| 91 elif file_path == 'error.html': | 85 elif file_path == 'error.html': |
| 92 raise Exception('Expected exception') | 86 raise Exception('Expected exception') |
| 93 | 87 |
| 94 | 88 |
| 95 # TODO(eyaich@): add the actual unittest for start-up retrying logic. | |
| 96 class BrowserStartFailureIntegrationUnittest( | 89 class BrowserStartFailureIntegrationUnittest( |
| 97 gpu_integration_test.GpuIntegrationTest): | 90 gpu_integration_test.GpuIntegrationTest): |
| 98 # Must be class-scoped since instances aren't reused across runs. | 91 |
| 99 _num_restart_failures = 0 | 92 _num_browser_crashes = 0 |
| 100 | 93 |
| 101 @classmethod | 94 @classmethod |
| 102 def setUpClass(cls): | 95 def setUpClass(cls): |
| 103 finder_options = fakes.CreateBrowserFinderOptions() | 96 cls._fake_browser_options = \ |
| 104 finder_options.browser_options.platform = fakes.FakeLinuxPlatform() | 97 fakes.CreateBrowserFinderOptions(execute_on_startup=cls.CrashOnStart) |
| 105 finder_options.output_formats = ['none'] | 98 cls._fake_browser_options.browser_options.platform = \ |
| 106 finder_options.suppress_gtest_report = True | 99 fakes.FakeLinuxPlatform() |
| 107 finder_options.output_dir = None | 100 cls._fake_browser_options.output_formats = ['none'] |
| 108 finder_options .upload_bucket = 'public' | 101 cls._fake_browser_options.suppress_gtest_report = True |
| 109 finder_options .upload_results = False | 102 cls._fake_browser_options.output_dir = None |
| 110 cls._finder_options = finder_options | 103 cls._fake_browser_options .upload_bucket = 'public' |
| 104 cls._fake_browser_options .upload_results = False | |
| 105 cls._finder_options = cls._fake_browser_options | |
| 111 cls.platform = None | 106 cls.platform = None |
| 112 cls.browser = None | 107 cls.browser = None |
| 113 cls.SetBrowserOptions(cls._finder_options) | 108 cls.SetBrowserOptions(cls._finder_options) |
| 114 cls.StartBrowser() | 109 cls.StartBrowser() |
| 115 | 110 |
| 116 @classmethod | 111 @classmethod |
| 117 def _CreateExpectations(cls): | 112 def _CreateExpectations(cls): |
| 118 expectations = gpu_test_expectations.GpuTestExpectations() | 113 expectations = gpu_test_expectations.GpuTestExpectations() |
| 119 expectations.Fail('expected_failure') | 114 expectations.Fail('expected_failure') |
| 120 expectations.Flaky('expected_flaky', max_num_retries=3) | 115 expectations.Flaky('expected_flaky', max_num_retries=3) |
| 121 expectations.Skip('expected_skip') | 116 expectations.Skip('expected_skip') |
| 122 return expectations | 117 return expectations |
| 123 | 118 |
| 124 @classmethod | 119 @classmethod |
| 120 def CrashOnStart(cls): | |
|
nednguyen
2016/08/08 15:04:30
nit: also probably keep the counter on how many ti
eyaich
2016/08/08 16:01:32
Done.
| |
| 121 if cls._num_browser_crashes < 2: | |
| 122 cls._num_browser_crashes += 1 | |
| 123 raise | |
| 124 | |
| 125 @classmethod | |
| 125 def Name(cls): | 126 def Name(cls): |
| 126 return 'browser_start_failure_integration_unittest' | 127 return 'browser_start_failure_integration_unittest' |
| 127 | 128 |
| 128 @classmethod | 129 @classmethod |
| 129 def GenerateGpuTests(cls, options): | 130 def GenerateGpuTests(cls, options): |
| 130 # This test causes the browser to try and restart the browser 3 times. | 131 # This test causes the browser to try and restart the browser 3 times. |
| 131 yield ('restart', 'restart.html', ()) | 132 yield ('restart', 'restart.html', ()) |
| 132 | 133 |
| 133 def RunActualGpuTest(self, file_path, *args): | 134 def RunActualGpuTest(self, file_path, *args): |
| 134 if file_path == 'restart.html': | 135 # The logic of this test is run when the browser starts, it fails twice |
| 135 try: | 136 # and then succeeds on the third time so we are just testing that this |
| 136 # This will fail because the browser is already started | 137 # is successful based on the parameters. |
| 137 self.StartBrowser() | 138 pass |
| 138 finally: | |
| 139 self.StopBrowser() | |
| 140 | 139 |
| 141 | 140 |
| 142 class GpuIntegrationTestUnittest(unittest.TestCase): | 141 class GpuIntegrationTestUnittest(unittest.TestCase): |
| 143 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') | 142 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') |
| 144 def testSimpleIntegrationUnittest(self, mockInitDependencyManager): | 143 def testSimpleIntegrationUnittest(self, mockInitDependencyManager): |
| 145 self._RunIntegrationTest( | 144 self._RunIntegrationTest( |
| 146 'simple_integration_unittest', [ | 145 'simple_integration_unittest', [ |
| 147 'expected_failure', | 146 'expected_failure', |
| 148 'setup', | 147 'setup', |
| 149 'unexpected_error', | 148 'unexpected_error', |
| 150 'unexpected_failure'], ['expected_flaky']) | 149 'unexpected_failure'], ['expected_flaky']) |
| 151 # It might be nice to be more precise about the order of operations | 150 # It might be nice to be more precise about the order of operations |
| 152 # with these browser restarts, but this is at least a start. | 151 # with these browser restarts, but this is at least a start. |
| 153 self.assertEquals(SimpleIntegrationUnittest._num_browser_starts, 6) | 152 self.assertEquals(SimpleIntegrationUnittest._num_browser_starts, 6) |
| 154 | 153 |
| 155 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') | 154 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') |
| 156 def testIntegrationUnittestWithBrowserFailure( | 155 def testIntegrationUnittestWithBrowserFailure( |
| 157 self, mockInitDependencyManager): | 156 self, mockInitDependencyManager): |
| 158 self._RunIntegrationTest( | 157 self._RunIntegrationTest( |
| 159 'browser_start_failure_integration_unittest', ['restart'], []) | 158 'browser_start_failure_integration_unittest', [], ['restart']) |
| 159 self.assertEquals( \ | |
| 160 BrowserStartFailureIntegrationUnittest._num_browser_crashes, 2) | |
| 160 | 161 |
| 161 def _RunIntegrationTest(self, test_name, failures, successes): | 162 def _RunIntegrationTest(self, test_name, failures, successes): |
| 162 options = browser_test_runner.TestRunOptions() | 163 options = browser_test_runner.TestRunOptions() |
| 163 # Suppress printing out information for passing tests. | 164 # Suppress printing out information for passing tests. |
| 164 options.verbosity = 0 | 165 options.verbosity = 0 |
| 165 config = gpu_project_config.CONFIG | 166 config = gpu_project_config.CONFIG |
| 166 temp_file = tempfile.NamedTemporaryFile(delete=False) | 167 temp_file = tempfile.NamedTemporaryFile(delete=False) |
| 167 temp_file.close() | 168 temp_file.close() |
| 168 temp_file_name = temp_file.name | 169 temp_file_name = temp_file.name |
| 169 try: | 170 try: |
| 170 browser_test_runner.Run( | 171 browser_test_runner.Run( |
| 171 config, options, | 172 config, options, |
| 172 [test_name, | 173 [test_name, |
| 173 '--write-abbreviated-json-results-to=%s' % temp_file_name]) | 174 '--write-abbreviated-json-results-to=%s' % temp_file_name]) |
| 174 with open(temp_file_name) as f: | 175 with open(temp_file_name) as f: |
| 175 test_result = json.load(f) | 176 test_result = json.load(f) |
| 176 self.assertEquals(test_result['failures'], failures) | 177 self.assertEquals(test_result['failures'], failures) |
| 177 self.assertEquals(test_result['successes'], successes) | 178 self.assertEquals(test_result['successes'], successes) |
| 178 self.assertEquals(test_result['valid'], True) | 179 self.assertEquals(test_result['valid'], True) |
| 179 | 180 |
| 180 finally: | 181 finally: |
| 181 os.remove(temp_file_name) | 182 os.remove(temp_file_name) |
| OLD | NEW |