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

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

Issue 2209673003: Unittest for pushing the restart logic into start browser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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 class BrowserStartFailureIntegrationUnittest(
96 gpu_integration_test.GpuIntegrationTest):
97 # Must be class-scoped since instances aren't reused across runs.
98 _num_restart_failures = 0
99
100 @classmethod
101 def setUpClass(cls):
102 finder_options = fakes.CreateBrowserFinderOptions()
103 finder_options.browser_options.platform = fakes.FakeLinuxPlatform()
104 finder_options.output_formats = ['none']
105 finder_options.suppress_gtest_report = True
106 finder_options.output_dir = None
107 finder_options .upload_bucket = 'public'
108 finder_options .upload_results = False
109 cls._finder_options = finder_options
110 cls.platform = None
111 cls.browser = None
112 cls.SetBrowserOptions(cls._finder_options)
113 cls.StartBrowser()
114
115 @classmethod
116 def _CreateExpectations(cls):
117 expectations = gpu_test_expectations.GpuTestExpectations()
118 expectations.Fail('expected_failure')
119 expectations.Flaky('expected_flaky', max_num_retries=3)
120 expectations.Skip('expected_skip')
121 return expectations
122
123 @classmethod
124 def Name(cls):
125 return 'browser_start_failure_integration_unittest'
126
127 @classmethod
128 def GenerateGpuTests(cls, options):
129 # This test causes the browser to try and restart the browser 3 times.
130 yield ('restart', 'restart.html', ())
131
132 def RunActualGpuTest(self, file_path, *args):
133 if file_path == 'restart.html':
134 try:
135 # This will fail because the browser is already started
136 self.StartBrowser()
137 finally:
138 self.StopBrowser()
139
140
112 class GpuIntegrationTestUnittest(unittest.TestCase): 141 class GpuIntegrationTestUnittest(unittest.TestCase):
113 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') 142 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager')
114 def testSimpleIntegrationUnittest(self, mockInitDependencyManager): 143 def testSimpleIntegrationUnittest(self, mockInitDependencyManager):
144 self._RunIntegrationTest(
145 'simple_integration_unittest', [
146 'expected_failure',
147 'setup',
148 'unexpected_error',
149 'unexpected_failure'], ['expected_flaky'])
150 # It might be nice to be more precise about the order of operations
151 # with these browser restarts, but this is at least a start.
152 self.assertEquals(SimpleIntegrationUnittest._num_browser_starts, 6)
153
154 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager')
155 def testIntegrationUnittestWithBrowserFailure(
156 self, mockInitDependencyManager):
157 self._RunIntegrationTest(
158 'browser_start_failure_integration_unittest', ['restart'], [])
159
160 def _RunIntegrationTest(self, test_name, failures, successes):
115 options = browser_test_runner.TestRunOptions() 161 options = browser_test_runner.TestRunOptions()
116 # Suppress printing out information for passing tests. 162 # Suppress printing out information for passing tests.
117 options.verbosity = 0 163 options.verbosity = 0
118 config = gpu_project_config.CONFIG 164 config = gpu_project_config.CONFIG
119 temp_file = tempfile.NamedTemporaryFile(delete=False) 165 temp_file = tempfile.NamedTemporaryFile(delete=False)
120 temp_file.close() 166 temp_file.close()
121 temp_file_name = temp_file.name 167 temp_file_name = temp_file.name
122 try: 168 try:
123 browser_test_runner.Run( 169 browser_test_runner.Run(
124 config, options, 170 config, options,
125 ['simple_integration_unittest', 171 [test_name,
126 '--write-abbreviated-json-results-to=%s' % temp_file_name]) 172 '--write-abbreviated-json-results-to=%s' % temp_file_name])
127 with open(temp_file_name) as f: 173 with open(temp_file_name) as f:
128 test_result = json.load(f) 174 test_result = json.load(f)
129 self.assertEquals(test_result['failures'], [ 175 self.assertEquals(test_result['failures'], failures)
130 'expected_failure', 176 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) 177 self.assertEquals(test_result['valid'], True)
137 # It might be nice to be more precise about the order of operations 178
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: 179 finally:
143 os.remove(temp_file_name) 180 os.remove(temp_file_name)
181
nednguyen 2016/08/04 17:03:48 nits: this extra blank line is not needed
eyaich 2016/08/04 18:15:17 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698