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

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

Issue 2181673002: Adding 3 attempts at starting the browser for a gpu integration test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding unittest coverage 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
20 21
21 class SimpleIntegrationUnittest(gpu_integration_test.GpuIntegrationTest): 22 class SimpleIntegrationUnittest(gpu_integration_test.GpuIntegrationTest):
22 # Must be class-scoped since instances aren't reused across runs. 23 # Must be class-scoped since instances aren't reused across runs.
23 _num_flaky_runs_to_fail = 2 24 _num_flaky_runs_to_fail = 2
24 25
25 _num_browser_starts = 0 26 _num_browser_starts = 0
26 27
28 _num_restart_failures = 0
29
27 @classmethod 30 @classmethod
28 def Name(cls): 31 def Name(cls):
29 return 'simple_integration_unittest' 32 return 'simple_integration_unittest'
30 33
31 def setUp(self): 34 def setUp(self):
32 global _GLOBAL_TEST_COUNT 35 global _GLOBAL_TEST_COUNT
33 _GLOBAL_TEST_COUNT += 1 36 _GLOBAL_TEST_COUNT += 1
34 # If this is the first test, fail on setup to ensure that the 37 # If this is the first test, fail on setup to ensure that the
35 # gpu_integration_test handles failures in setup and remaining tests 38 # gpu_integration_test handles failures in setup and remaining tests
36 # can be executed 39 # can be executed
(...skipping 17 matching lines...) Expand all
54 cls.StartBrowser() 57 cls.StartBrowser()
55 58
56 @classmethod 59 @classmethod
57 def GenerateGpuTests(cls, options): 60 def GenerateGpuTests(cls, options):
58 yield ('setup', 'failure.html', ()) 61 yield ('setup', 'failure.html', ())
59 yield ('expected_failure', 'failure.html', ()) 62 yield ('expected_failure', 'failure.html', ())
60 yield ('expected_flaky', 'flaky.html', ()) 63 yield ('expected_flaky', 'flaky.html', ())
61 yield ('expected_skip', 'failure.html', ()) 64 yield ('expected_skip', 'failure.html', ())
62 yield ('unexpected_failure', 'failure.html', ()) 65 yield ('unexpected_failure', 'failure.html', ())
63 yield ('unexpected_error', 'error.html', ()) 66 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', ())
64 70
65 @classmethod 71 @classmethod
66 def _CreateExpectations(cls): 72 def _CreateExpectations(cls):
67 expectations = gpu_test_expectations.GpuTestExpectations() 73 expectations = gpu_test_expectations.GpuTestExpectations()
68 expectations.Fail('expected_failure') 74 expectations.Fail('expected_failure')
69 expectations.Flaky('expected_flaky', max_num_retries=3) 75 expectations.Flaky('expected_flaky', max_num_retries=3)
70 expectations.Skip('expected_skip') 76 expectations.Skip('expected_skip')
71 return expectations 77 return expectations
72 78
73 @classmethod 79 @classmethod
74 def StartBrowser(cls): 80 def StartBrowser(cls):
75 super(SimpleIntegrationUnittest, cls).StartBrowser() 81 super(SimpleIntegrationUnittest, cls).StartBrowser()
76 cls._num_browser_starts += 1 82 cls._num_browser_starts += 1
77 83
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
78 def RunActualGpuTest(self, file_path, *args): 97 def RunActualGpuTest(self, file_path, *args):
79 if file_path == 'failure.html': 98 if file_path == 'failure.html':
80 self.fail('Expected failure') 99 self.fail('Expected failure')
100 elif file_path == 'restart.html':
101 global _GLOBAL_RESTART_CRASH
102 _GLOBAL_RESTART_CRASH = True
103 self._RestartBrowser("testing restart on failure")
81 elif file_path == 'flaky.html': 104 elif file_path == 'flaky.html':
82 if self.__class__._num_flaky_runs_to_fail > 0: 105 if self.__class__._num_flaky_runs_to_fail > 0:
83 self.__class__._num_flaky_runs_to_fail -= 1 106 self.__class__._num_flaky_runs_to_fail -= 1
84 self.fail('Expected flaky failure') 107 self.fail('Expected flaky failure')
85 elif file_path == 'error.html': 108 elif file_path == 'error.html':
86 raise Exception('Expected exception') 109 raise Exception('Expected exception')
87 110
88 111
89 class GpuIntegrationTestUnittest(unittest.TestCase): 112 class GpuIntegrationTestUnittest(unittest.TestCase):
90 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager') 113 @mock.patch('telemetry.internal.util.binary_manager.InitDependencyManager')
(...skipping 11 matching lines...) Expand all
102 ['simple_integration_unittest', 125 ['simple_integration_unittest',
103 '--write-abbreviated-json-results-to=%s' % temp_file_name]) 126 '--write-abbreviated-json-results-to=%s' % temp_file_name])
104 with open(temp_file_name) as f: 127 with open(temp_file_name) as f:
105 test_result = json.load(f) 128 test_result = json.load(f)
106 self.assertEquals(test_result['failures'], [ 129 self.assertEquals(test_result['failures'], [
107 'expected_failure', 130 'expected_failure',
108 'setup', 131 'setup',
109 'unexpected_error', 132 'unexpected_error',
110 'unexpected_failure']) 133 'unexpected_failure'])
111 self.assertEquals(test_result['successes'], [ 134 self.assertEquals(test_result['successes'], [
112 'expected_flaky']) 135 'expected_flaky', 'restart'])
113 self.assertEquals(test_result['valid'], True) 136 self.assertEquals(test_result['valid'], True)
114 # It might be nice to be more precise about the order of operations 137 # It might be nice to be more precise about the order of operations
115 # with these browser restarts, but this is at least a start. 138 # with these browser restarts, but this is at least a start.
116 self.assertEquals(SimpleIntegrationUnittest._num_browser_starts, 6) 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)
117 finally: 142 finally:
118 os.remove(temp_file_name) 143 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