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

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

Issue 2219593003: [content/test/gpu] Pushing the restart logic into start browser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add TODO Created 4 years, 4 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
« no previous file with comments | « content/test/gpu/gpu_tests/gpu_integration_test.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 mock 6 import mock
7 import os 7 import os
8 import tempfile 8 import tempfile
9 import unittest 9 import unittest
10 10
11 from telemetry.testing import fakes 11 from telemetry.testing import fakes
12 from telemetry.testing import browser_test_runner 12 from telemetry.testing import browser_test_runner
13 13
14 import gpu_project_config 14 import gpu_project_config
15 15
16 from gpu_tests import gpu_integration_test 16 from gpu_tests import gpu_integration_test
17 from gpu_tests import gpu_test_expectations 17 from gpu_tests import gpu_test_expectations
18 18
19 _GLOBAL_TEST_COUNT = 0 19 _GLOBAL_TEST_COUNT = 0
20 _GLOBAL_RESTART_CRASH = False
21 20
22 class SimpleIntegrationUnittest(gpu_integration_test.GpuIntegrationTest): 21 class SimpleIntegrationUnittest(gpu_integration_test.GpuIntegrationTest):
23 # Must be class-scoped since instances aren't reused across runs. 22 # Must be class-scoped since instances aren't reused across runs.
24 _num_flaky_runs_to_fail = 2 23 _num_flaky_runs_to_fail = 2
25 24
26 _num_browser_starts = 0 25 _num_browser_starts = 0
27 26
28 _num_restart_failures = 0
29
30 @classmethod 27 @classmethod
31 def Name(cls): 28 def Name(cls):
32 return 'simple_integration_unittest' 29 return 'simple_integration_unittest'
33 30
34 def setUp(self): 31 def setUp(self):
35 global _GLOBAL_TEST_COUNT 32 global _GLOBAL_TEST_COUNT
36 _GLOBAL_TEST_COUNT += 1 33 _GLOBAL_TEST_COUNT += 1
37 # If this is the first test, fail on setup to ensure that the 34 # If this is the first test, fail on setup to ensure that the
38 # gpu_integration_test handles failures in setup and remaining tests 35 # gpu_integration_test handles failures in setup and remaining tests
39 # can be executed 36 # can be executed
40 if _GLOBAL_TEST_COUNT == 1: 37 if _GLOBAL_TEST_COUNT == 1:
41 self.tab.Navigate('chrome://crash') 38 self.tab.Navigate('chrome://crash')
42 super(SimpleIntegrationUnittest, self).setUp() 39 super(SimpleIntegrationUnittest, self).setUp()
43 40
44 @classmethod 41 @classmethod
45 def setUpClass(cls): 42 def setUpClass(cls):
46 finder_options = fakes.CreateBrowserFinderOptions() 43 finder_options = fakes.CreateBrowserFinderOptions()
47 finder_options.browser_options.platform = fakes.FakeLinuxPlatform() 44 finder_options.browser_options.platform = fakes.FakeLinuxPlatform()
48 finder_options.output_formats = ['none'] 45 finder_options.output_formats = ['none']
49 finder_options.suppress_gtest_report = True 46 finder_options.suppress_gtest_report = True
50 finder_options.output_dir = None 47 finder_options.output_dir = None
51 finder_options.upload_bucket = 'public' 48 finder_options .upload_bucket = 'public'
52 finder_options.upload_results = False 49 finder_options .upload_results = False
53 cls._finder_options = finder_options 50 cls._finder_options = finder_options
54 cls.platform = None 51 cls.platform = None
55 cls.browser = None 52 cls.browser = None
56 cls.SetBrowserOptions(cls._finder_options) 53 cls.SetBrowserOptions(cls._finder_options)
57 cls.StartBrowser() 54 cls.StartBrowser()
58 55
59 @classmethod 56 @classmethod
60 def GenerateGpuTests(cls, options): 57 def GenerateGpuTests(cls, options):
61 yield ('setup', 'failure.html', ()) 58 yield ('setup', 'failure.html', ())
62 yield ('expected_failure', 'failure.html', ()) 59 yield ('expected_failure', 'failure.html', ())
63 yield ('expected_flaky', 'flaky.html', ()) 60 yield ('expected_flaky', 'flaky.html', ())
64 yield ('expected_skip', 'failure.html', ()) 61 yield ('expected_skip', 'failure.html', ())
65 yield ('unexpected_failure', 'failure.html', ()) 62 yield ('unexpected_failure', 'failure.html', ())
66 yield ('unexpected_error', 'error.html', ()) 63 yield ('unexpected_error', 'error.html', ())
67 # This test causes the browser to restart 2 times (max allowed 3) and then
68 # succeeds on the third attempt
69 yield ('restart', 'restart.html', ())
70 64
71 @classmethod 65 @classmethod
72 def _CreateExpectations(cls): 66 def _CreateExpectations(cls):
73 expectations = gpu_test_expectations.GpuTestExpectations() 67 expectations = gpu_test_expectations.GpuTestExpectations()
74 expectations.Fail('expected_failure') 68 expectations.Fail('expected_failure')
75 expectations.Flaky('expected_flaky', max_num_retries=3) 69 expectations.Flaky('expected_flaky', max_num_retries=3)
76 expectations.Skip('expected_skip') 70 expectations.Skip('expected_skip')
77 return expectations 71 return expectations
78 72
79 @classmethod 73 @classmethod
80 def StartBrowser(cls): 74 def StartBrowser(cls):
81 super(SimpleIntegrationUnittest, cls).StartBrowser() 75 super(SimpleIntegrationUnittest, cls).StartBrowser()
82 cls._num_browser_starts += 1 76 cls._num_browser_starts += 1
83 77
84 @classmethod
85 def StopBrowser(cls):
86 global _GLOBAL_RESTART_CRASH
87 if _GLOBAL_RESTART_CRASH:
88 if cls._num_restart_failures < 2:
89 cls._num_restart_failures += 1
90 raise Exception
91 else:
92 _GLOBAL_RESTART_CRASH = False
93
94 super(SimpleIntegrationUnittest, cls).StopBrowser()
95
96
97 def RunActualGpuTest(self, file_path, *args): 78 def RunActualGpuTest(self, file_path, *args):
98 if file_path == 'failure.html': 79 if file_path == 'failure.html':
99 self.fail('Expected failure') 80 self.fail('Expected failure')
100 elif file_path == 'restart.html': 81 elif file_path == 'restart.html':
101 global _GLOBAL_RESTART_CRASH 82 try:
102 _GLOBAL_RESTART_CRASH = True 83 # This will fail because the browser is already started
103 self._RestartBrowser("testing restart on failure") 84 self.StartBrowser()
85 finally:
86 self.StopBrowser()
104 elif file_path == 'flaky.html': 87 elif file_path == 'flaky.html':
105 if self.__class__._num_flaky_runs_to_fail > 0: 88 if self.__class__._num_flaky_runs_to_fail > 0:
106 self.__class__._num_flaky_runs_to_fail -= 1 89 self.__class__._num_flaky_runs_to_fail -= 1
107 self.fail('Expected flaky failure') 90 self.fail('Expected flaky failure')
108 elif file_path == 'error.html': 91 elif file_path == 'error.html':
109 raise Exception('Expected exception') 92 raise Exception('Expected exception')
110 93
111 94
95 # TODO(eyaich@): add the actual unittest for start-up retrying logic.
96 class BrowserStartFailureIntegrationUnittest(
97 gpu_integration_test.GpuIntegrationTest):
98 # Must be class-scoped since instances aren't reused across runs.
99 _num_restart_failures = 0
100
101 @classmethod
102 def setUpClass(cls):
103 finder_options = fakes.CreateBrowserFinderOptions()
104 finder_options.browser_options.platform = fakes.FakeLinuxPlatform()
105 finder_options.output_formats = ['none']
106 finder_options.suppress_gtest_report = True
107 finder_options.output_dir = None
108 finder_options .upload_bucket = 'public'
109 finder_options .upload_results = False
110 cls._finder_options = finder_options
111 cls.platform = None
112 cls.browser = None
113 cls.SetBrowserOptions(cls._finder_options)
114 cls.StartBrowser()
115
116 @classmethod
117 def _CreateExpectations(cls):
118 expectations = gpu_test_expectations.GpuTestExpectations()
119 expectations.Fail('expected_failure')
120 expectations.Flaky('expected_flaky', max_num_retries=3)
121 expectations.Skip('expected_skip')
122 return expectations
123
124 @classmethod
125 def Name(cls):
126 return 'browser_start_failure_integration_unittest'
127
128 @classmethod
129 def GenerateGpuTests(cls, options):
130 # This test causes the browser to try and restart the browser 3 times.
131 yield ('restart', 'restart.html', ())
132
133 def RunActualGpuTest(self, file_path, *args):
134 if file_path == 'restart.html':
135 try:
136 # This will fail because the browser is already started
137 self.StartBrowser()
138 finally:
139 self.StopBrowser()
140
141
112 class GpuIntegrationTestUnittest(unittest.TestCase): 142 class GpuIntegrationTestUnittest(unittest.TestCase):
113 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') 143 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager')
114 def testSimpleIntegrationUnittest(self, mockInitDependencyManager): 144 def testSimpleIntegrationUnittest(self, mockInitDependencyManager):
145 self._RunIntegrationTest(
146 'simple_integration_unittest', [
147 'expected_failure',
148 'setup',
149 'unexpected_error',
150 'unexpected_failure'], ['expected_flaky'])
151 # 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 self.assertEquals(SimpleIntegrationUnittest._num_browser_starts, 6)
154
155 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager')
156 def testIntegrationUnittestWithBrowserFailure(
157 self, mockInitDependencyManager):
158 self._RunIntegrationTest(
159 'browser_start_failure_integration_unittest', ['restart'], [])
160
161 def _RunIntegrationTest(self, test_name, failures, successes):
115 options = browser_test_runner.TestRunOptions() 162 options = browser_test_runner.TestRunOptions()
116 # Suppress printing out information for passing tests. 163 # Suppress printing out information for passing tests.
117 options.verbosity = 0 164 options.verbosity = 0
118 config = gpu_project_config.CONFIG 165 config = gpu_project_config.CONFIG
119 temp_file = tempfile.NamedTemporaryFile(delete=False) 166 temp_file = tempfile.NamedTemporaryFile(delete=False)
120 temp_file.close() 167 temp_file.close()
121 temp_file_name = temp_file.name 168 temp_file_name = temp_file.name
122 try: 169 try:
123 browser_test_runner.Run( 170 browser_test_runner.Run(
124 config, options, 171 config, options,
125 ['simple_integration_unittest', 172 [test_name,
126 '--write-abbreviated-json-results-to=%s' % temp_file_name]) 173 '--write-abbreviated-json-results-to=%s' % temp_file_name])
127 with open(temp_file_name) as f: 174 with open(temp_file_name) as f:
128 test_result = json.load(f) 175 test_result = json.load(f)
129 self.assertEquals(test_result['failures'], [ 176 self.assertEquals(test_result['failures'], failures)
130 'expected_failure', 177 self.assertEquals(test_result['successes'], successes)
131 'setup',
132 'unexpected_error',
133 'unexpected_failure'])
134 self.assertEquals(test_result['successes'], [
135 'expected_flaky', 'restart'])
136 self.assertEquals(test_result['valid'], True) 178 self.assertEquals(test_result['valid'], True)
137 # It might be nice to be more precise about the order of operations 179
138 # with these browser restarts, but this is at least a start.
139 self.assertEquals(SimpleIntegrationUnittest._num_browser_starts, 7)
140 # Assert that we restarted the browser 2 times due to failure in restart
141 self.assertEquals(SimpleIntegrationUnittest._num_restart_failures, 2)
142 finally: 180 finally:
143 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') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698