| 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 |
| 93 _num_browser_starts = 0 |
| 100 | 94 |
| 101 @classmethod | 95 @classmethod |
| 102 def setUpClass(cls): | 96 def setUpClass(cls): |
| 103 finder_options = fakes.CreateBrowserFinderOptions() | 97 cls._fake_browser_options = \ |
| 104 finder_options.browser_options.platform = fakes.FakeLinuxPlatform() | 98 fakes.CreateBrowserFinderOptions(execute_on_startup=cls.CrashOnStart) |
| 105 finder_options.output_formats = ['none'] | 99 cls._fake_browser_options.browser_options.platform = \ |
| 106 finder_options.suppress_gtest_report = True | 100 fakes.FakeLinuxPlatform() |
| 107 finder_options.output_dir = None | 101 cls._fake_browser_options.output_formats = ['none'] |
| 108 finder_options .upload_bucket = 'public' | 102 cls._fake_browser_options.suppress_gtest_report = True |
| 109 finder_options .upload_results = False | 103 cls._fake_browser_options.output_dir = None |
| 110 cls._finder_options = finder_options | 104 cls._fake_browser_options .upload_bucket = 'public' |
| 105 cls._fake_browser_options .upload_results = False |
| 106 cls._finder_options = cls._fake_browser_options |
| 111 cls.platform = None | 107 cls.platform = None |
| 112 cls.browser = None | 108 cls.browser = None |
| 113 cls.SetBrowserOptions(cls._finder_options) | 109 cls.SetBrowserOptions(cls._finder_options) |
| 114 cls.StartBrowser() | 110 cls.StartBrowser() |
| 115 | 111 |
| 116 @classmethod | 112 @classmethod |
| 117 def _CreateExpectations(cls): | 113 def _CreateExpectations(cls): |
| 118 expectations = gpu_test_expectations.GpuTestExpectations() | 114 expectations = gpu_test_expectations.GpuTestExpectations() |
| 119 expectations.Fail('expected_failure') | 115 expectations.Fail('expected_failure') |
| 120 expectations.Flaky('expected_flaky', max_num_retries=3) | 116 expectations.Flaky('expected_flaky', max_num_retries=3) |
| 121 expectations.Skip('expected_skip') | 117 expectations.Skip('expected_skip') |
| 122 return expectations | 118 return expectations |
| 123 | 119 |
| 124 @classmethod | 120 @classmethod |
| 121 def CrashOnStart(cls): |
| 122 cls._num_browser_starts += 1 |
| 123 if cls._num_browser_crashes < 2: |
| 124 cls._num_browser_crashes += 1 |
| 125 raise |
| 126 |
| 127 @classmethod |
| 125 def Name(cls): | 128 def Name(cls): |
| 126 return 'browser_start_failure_integration_unittest' | 129 return 'browser_start_failure_integration_unittest' |
| 127 | 130 |
| 128 @classmethod | 131 @classmethod |
| 129 def GenerateGpuTests(cls, options): | 132 def GenerateGpuTests(cls, options): |
| 130 # This test causes the browser to try and restart the browser 3 times. | 133 # This test causes the browser to try and restart the browser 3 times. |
| 131 yield ('restart', 'restart.html', ()) | 134 yield ('restart', 'restart.html', ()) |
| 132 | 135 |
| 133 def RunActualGpuTest(self, file_path, *args): | 136 def RunActualGpuTest(self, file_path, *args): |
| 134 if file_path == 'restart.html': | 137 # The logic of this test is run when the browser starts, it fails twice |
| 135 try: | 138 # and then succeeds on the third time so we are just testing that this |
| 136 # This will fail because the browser is already started | 139 # is successful based on the parameters. |
| 137 self.StartBrowser() | 140 pass |
| 138 finally: | |
| 139 self.StopBrowser() | |
| 140 | 141 |
| 141 | 142 |
| 142 class GpuIntegrationTestUnittest(unittest.TestCase): | 143 class GpuIntegrationTestUnittest(unittest.TestCase): |
| 143 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') | 144 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') |
| 144 def testSimpleIntegrationUnittest(self, mockInitDependencyManager): | 145 def testSimpleIntegrationUnittest(self, mockInitDependencyManager): |
| 145 self._RunIntegrationTest( | 146 self._RunIntegrationTest( |
| 146 'simple_integration_unittest', [ | 147 'simple_integration_unittest', [ |
| 147 'expected_failure', | 148 'expected_failure', |
| 148 'setup', | 149 'setup', |
| 149 'unexpected_error', | 150 'unexpected_error', |
| 150 'unexpected_failure'], ['expected_flaky']) | 151 'unexpected_failure'], ['expected_flaky']) |
| 151 # It might be nice to be more precise about the order of operations | 152 # 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. | 153 # with these browser restarts, but this is at least a start. |
| 153 self.assertEquals(SimpleIntegrationUnittest._num_browser_starts, 6) | 154 self.assertEquals(SimpleIntegrationUnittest._num_browser_starts, 6) |
| 154 | 155 |
| 155 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') | 156 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') |
| 156 def testIntegrationUnittestWithBrowserFailure( | 157 def testIntegrationUnittestWithBrowserFailure( |
| 157 self, mockInitDependencyManager): | 158 self, mockInitDependencyManager): |
| 158 self._RunIntegrationTest( | 159 self._RunIntegrationTest( |
| 159 'browser_start_failure_integration_unittest', ['restart'], []) | 160 'browser_start_failure_integration_unittest', [], ['restart']) |
| 161 self.assertEquals( \ |
| 162 BrowserStartFailureIntegrationUnittest._num_browser_crashes, 2) |
| 163 self.assertEquals( \ |
| 164 BrowserStartFailureIntegrationUnittest._num_browser_starts, 3) |
| 160 | 165 |
| 161 def _RunIntegrationTest(self, test_name, failures, successes): | 166 def _RunIntegrationTest(self, test_name, failures, successes): |
| 162 options = browser_test_runner.TestRunOptions() | 167 options = browser_test_runner.TestRunOptions() |
| 163 # Suppress printing out information for passing tests. | 168 # Suppress printing out information for passing tests. |
| 164 options.verbosity = 0 | 169 options.verbosity = 0 |
| 165 config = gpu_project_config.CONFIG | 170 config = gpu_project_config.CONFIG |
| 166 temp_file = tempfile.NamedTemporaryFile(delete=False) | 171 temp_file = tempfile.NamedTemporaryFile(delete=False) |
| 167 temp_file.close() | 172 temp_file.close() |
| 168 temp_file_name = temp_file.name | 173 temp_file_name = temp_file.name |
| 169 try: | 174 try: |
| 170 browser_test_runner.Run( | 175 browser_test_runner.Run( |
| 171 config, options, | 176 config, options, |
| 172 [test_name, | 177 [test_name, |
| 173 '--write-abbreviated-json-results-to=%s' % temp_file_name]) | 178 '--write-abbreviated-json-results-to=%s' % temp_file_name]) |
| 174 with open(temp_file_name) as f: | 179 with open(temp_file_name) as f: |
| 175 test_result = json.load(f) | 180 test_result = json.load(f) |
| 176 self.assertEquals(test_result['failures'], failures) | 181 self.assertEquals(test_result['failures'], failures) |
| 177 self.assertEquals(test_result['successes'], successes) | 182 self.assertEquals(test_result['successes'], successes) |
| 178 self.assertEquals(test_result['valid'], True) | 183 self.assertEquals(test_result['valid'], True) |
| 179 | 184 |
| 180 finally: | 185 finally: |
| 181 os.remove(temp_file_name) | 186 os.remove(temp_file_name) |
| OLD | NEW |