Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: content/test/gpu/gpu_tests/gpu_integration_test_unittest.py

Issue 2643023004: Fetch the first tab inside the browser startup retry loop. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 logging
6 import mock 7 import mock
7 import os 8 import os
8 import tempfile 9 import tempfile
9 import unittest 10 import unittest
10 11
11 from telemetry.testing import fakes 12 from telemetry.testing import fakes
12 from telemetry.testing import browser_test_runner 13 from telemetry.testing import browser_test_runner
13 14
14 import gpu_project_config 15 import gpu_project_config
15 16
16 from gpu_tests import gpu_integration_test 17 from gpu_tests import gpu_integration_test
17 from gpu_tests import gpu_test_expectations 18 from gpu_tests import gpu_test_expectations
18 19
19 _GLOBAL_TEST_COUNT = 0
20
21 class SimpleIntegrationUnittest(gpu_integration_test.GpuIntegrationTest): 20 class SimpleIntegrationUnittest(gpu_integration_test.GpuIntegrationTest):
22 # Must be class-scoped since instances aren't reused across runs. 21 # Must be class-scoped since instances aren't reused across runs.
23 _num_flaky_runs_to_fail = 2 22 _num_flaky_runs_to_fail = 2
24 23
25 _num_browser_starts = 0 24 _num_browser_starts = 0
26 25
27 @classmethod 26 @classmethod
28 def Name(cls): 27 def Name(cls):
29 return 'simple_integration_unittest' 28 return 'simple_integration_unittest'
30 29
31 def setUp(self): 30 def setUp(self):
32 global _GLOBAL_TEST_COUNT
33 _GLOBAL_TEST_COUNT += 1
34 # If this is the first test, fail on setup to ensure that the
35 # gpu_integration_test handles failures in setup and remaining tests
36 # can be executed
37 if _GLOBAL_TEST_COUNT == 1:
38 self.tab.Navigate('chrome://crash')
39 super(SimpleIntegrationUnittest, self).setUp() 31 super(SimpleIntegrationUnittest, self).setUp()
40 32
41 @classmethod 33 @classmethod
42 def setUpClass(cls): 34 def setUpClass(cls):
43 finder_options = fakes.CreateBrowserFinderOptions() 35 finder_options = fakes.CreateBrowserFinderOptions()
44 finder_options.browser_options.platform = fakes.FakeLinuxPlatform() 36 finder_options.browser_options.platform = fakes.FakeLinuxPlatform()
45 finder_options.output_formats = ['none'] 37 finder_options.output_formats = ['none']
46 finder_options.suppress_gtest_report = True 38 finder_options.suppress_gtest_report = True
47 finder_options.output_dir = None 39 finder_options.output_dir = None
48 finder_options .upload_bucket = 'public' 40 finder_options.upload_bucket = 'public'
49 finder_options .upload_results = False 41 finder_options.upload_results = False
50 cls._finder_options = finder_options 42 cls._finder_options = finder_options
51 cls.platform = None 43 cls.platform = None
52 cls.browser = None 44 cls.browser = None
53 cls.SetBrowserOptions(cls._finder_options) 45 cls.SetBrowserOptions(cls._finder_options)
54 cls.StartBrowser() 46 cls.StartBrowser()
55 47
56 @classmethod 48 @classmethod
57 def GenerateGpuTests(cls, options): 49 def GenerateGpuTests(cls, options):
58 yield ('setup', 'failure.html', ())
59 yield ('expected_failure', 'failure.html', ()) 50 yield ('expected_failure', 'failure.html', ())
60 yield ('expected_flaky', 'flaky.html', ()) 51 yield ('expected_flaky', 'flaky.html', ())
61 yield ('expected_skip', 'failure.html', ()) 52 yield ('expected_skip', 'failure.html', ())
62 yield ('unexpected_failure', 'failure.html', ()) 53 yield ('unexpected_failure', 'failure.html', ())
63 yield ('unexpected_error', 'error.html', ()) 54 yield ('unexpected_error', 'error.html', ())
64 55
65 @classmethod 56 @classmethod
66 def _CreateExpectations(cls): 57 def _CreateExpectations(cls):
67 expectations = gpu_test_expectations.GpuTestExpectations() 58 expectations = gpu_test_expectations.GpuTestExpectations()
68 expectations.Fail('expected_failure') 59 expectations.Fail('expected_failure')
69 expectations.Flaky('expected_flaky', max_num_retries=3) 60 expectations.Flaky('expected_flaky', max_num_retries=3)
70 expectations.Skip('expected_skip') 61 expectations.Skip('expected_skip')
71 return expectations 62 return expectations
72 63
73 @classmethod 64 @classmethod
74 def StartBrowser(cls): 65 def StartBrowser(cls):
75 super(SimpleIntegrationUnittest, cls).StartBrowser() 66 super(SimpleIntegrationUnittest, cls).StartBrowser()
76 cls._num_browser_starts += 1 67 cls._num_browser_starts += 1
77 68
78 def RunActualGpuTest(self, file_path, *args): 69 def RunActualGpuTest(self, file_path, *args):
70 logging.warn('Running ' + file_path)
79 if file_path == 'failure.html': 71 if file_path == 'failure.html':
80 self.fail('Expected failure') 72 self.fail('Expected failure')
81 elif file_path == 'flaky.html': 73 elif file_path == 'flaky.html':
82 if self.__class__._num_flaky_runs_to_fail > 0: 74 if self.__class__._num_flaky_runs_to_fail > 0:
83 self.__class__._num_flaky_runs_to_fail -= 1 75 self.__class__._num_flaky_runs_to_fail -= 1
84 self.fail('Expected flaky failure') 76 self.fail('Expected flaky failure')
85 elif file_path == 'error.html': 77 elif file_path == 'error.html':
86 raise Exception('Expected exception') 78 raise Exception('Expected exception')
87 79
88 80
(...skipping 15 matching lines...) Expand all
104 cls._fake_browser_options .upload_bucket = 'public' 96 cls._fake_browser_options .upload_bucket = 'public'
105 cls._fake_browser_options .upload_results = False 97 cls._fake_browser_options .upload_results = False
106 cls._finder_options = cls._fake_browser_options 98 cls._finder_options = cls._fake_browser_options
107 cls.platform = None 99 cls.platform = None
108 cls.browser = None 100 cls.browser = None
109 cls.SetBrowserOptions(cls._finder_options) 101 cls.SetBrowserOptions(cls._finder_options)
110 cls.StartBrowser() 102 cls.StartBrowser()
111 103
112 @classmethod 104 @classmethod
113 def _CreateExpectations(cls): 105 def _CreateExpectations(cls):
114 expectations = gpu_test_expectations.GpuTestExpectations() 106 return gpu_test_expectations.GpuTestExpectations()
115 expectations.Fail('expected_failure')
116 expectations.Flaky('expected_flaky', max_num_retries=3)
117 expectations.Skip('expected_skip')
118 return expectations
119 107
120 @classmethod 108 @classmethod
121 def CrashOnStart(cls): 109 def CrashOnStart(cls):
122 cls._num_browser_starts += 1 110 cls._num_browser_starts += 1
123 if cls._num_browser_crashes < 2: 111 if cls._num_browser_crashes < 2:
124 cls._num_browser_crashes += 1 112 cls._num_browser_crashes += 1
125 raise 113 raise
126 114
127 @classmethod 115 @classmethod
128 def Name(cls): 116 def Name(cls):
129 return 'browser_start_failure_integration_unittest' 117 return 'browser_start_failure_integration_unittest'
130 118
131 @classmethod 119 @classmethod
132 def GenerateGpuTests(cls, options): 120 def GenerateGpuTests(cls, options):
133 # This test causes the browser to try and restart the browser 3 times. 121 # This test causes the browser to try and restart the browser 3 times.
134 yield ('restart', 'restart.html', ()) 122 yield ('restart', 'restart.html', ())
135 123
136 def RunActualGpuTest(self, file_path, *args): 124 def RunActualGpuTest(self, file_path, *args):
137 # The logic of this test is run when the browser starts, it fails twice 125 # The logic of this test is run when the browser starts, it fails twice
138 # and then succeeds on the third time so we are just testing that this 126 # and then succeeds on the third time so we are just testing that this
139 # is successful based on the parameters. 127 # is successful based on the parameters.
140 pass 128 pass
141 129
142 130
143 class GpuIntegrationTestUnittest(unittest.TestCase): 131 class GpuIntegrationTestUnittest(unittest.TestCase):
144 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') 132 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager')
145 def testSimpleIntegrationUnittest(self, mockInitDependencyManager): 133 def testSimpleIntegrationUnittest(self, mockInitDependencyManager):
146 self._RunIntegrationTest( 134 self._RunIntegrationTest(
147 'simple_integration_unittest', [ 135 'simple_integration_unittest', [
148 'expected_failure', 136 'unexpected_error',
149 'setup', 137 'unexpected_failure'
150 'unexpected_error', 138 ], [
151 'unexpected_failure'], ['expected_flaky']) 139 'expected_failure',
140 'expected_flaky',
141 ])
152 # It might be nice to be more precise about the order of operations 142 # It might be nice to be more precise about the order of operations
153 # with these browser restarts, but this is at least a start. 143 # with these browser restarts, but this is at least a start.
154 self.assertEquals(SimpleIntegrationUnittest._num_browser_starts, 6) 144 self.assertEquals(SimpleIntegrationUnittest._num_browser_starts, 6)
155 145
156 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') 146 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager')
157 def testIntegrationUnittestWithBrowserFailure( 147 def testIntegrationUnittestWithBrowserFailure(
158 self, mockInitDependencyManager): 148 self, mockInitDependencyManager):
159 self._RunIntegrationTest( 149 self._RunIntegrationTest(
160 'browser_start_failure_integration_unittest', [], ['restart']) 150 'browser_start_failure_integration_unittest', [], ['restart'])
161 self.assertEquals( \ 151 self.assertEquals( \
162 BrowserStartFailureIntegrationUnittest._num_browser_crashes, 2) 152 BrowserStartFailureIntegrationUnittest._num_browser_crashes, 2)
163 self.assertEquals( \ 153 self.assertEquals( \
164 BrowserStartFailureIntegrationUnittest._num_browser_starts, 3) 154 BrowserStartFailureIntegrationUnittest._num_browser_starts, 3)
165 155
156 # TODO(kbr): write a new test utilizing the
157 # execute_after_browser_creation argument to
158 # fakes.CreateBrowserFinderOptions once that is available.
159 # crbug.com/682819
160
166 def _RunIntegrationTest(self, test_name, failures, successes): 161 def _RunIntegrationTest(self, test_name, failures, successes):
167 options = browser_test_runner.TestRunOptions() 162 options = browser_test_runner.TestRunOptions()
168 # Suppress printing out information for passing tests. 163 # Suppress printing out information for passing tests.
169 options.verbosity = 0 164 options.verbosity = 0
170 config = gpu_project_config.CONFIG 165 config = gpu_project_config.CONFIG
171 temp_file = tempfile.NamedTemporaryFile(delete=False) 166 temp_file = tempfile.NamedTemporaryFile(delete=False)
172 temp_file.close() 167 temp_file.close()
173 temp_file_name = temp_file.name 168 temp_file_name = temp_file.name
174 try: 169 try:
175 browser_test_runner.Run( 170 browser_test_runner.Run(
176 config, options, 171 config, options,
177 [test_name, 172 [test_name,
178 '--write-abbreviated-json-results-to=%s' % temp_file_name]) 173 '--write-abbreviated-json-results-to=%s' % temp_file_name])
179 with open(temp_file_name) as f: 174 with open(temp_file_name) as f:
180 test_result = json.load(f) 175 test_result = json.load(f)
181 self.assertEquals(test_result['failures'], failures) 176 self.assertEquals(test_result['failures'], failures)
182 self.assertEquals(test_result['successes'], successes) 177 self.assertEquals(test_result['successes'], successes)
183 self.assertEquals(test_result['valid'], True) 178 self.assertEquals(test_result['valid'], True)
184 179
185 finally: 180 finally:
186 os.remove(temp_file_name) 181 os.remove(temp_file_name)
OLDNEW
« no previous file with comments | « content/test/gpu/gpu_tests/gpu_integration_test.py ('k') | content/test/gpu/gpu_tests/gpu_process_integration_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698