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

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

Issue 1915033009: Handle Telemetry's TimeoutException in retries of flaky tests. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Redo patch to handle exceptions in DidRunStory. Created 4 years, 7 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 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 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 import unittest 4 import unittest
5 5
6 from telemetry import benchmark as benchmark_module 6 from telemetry import benchmark as benchmark_module
7 from telemetry.core import exceptions 7 from telemetry.core import exceptions
8 from telemetry.story import story_set as story_set_module 8 from telemetry.story import story_set as story_set_module
9 from telemetry.testing import fakes 9 from telemetry.testing import fakes
10 10
(...skipping 27 matching lines...) Expand all
38 self._times_to_fail = times_to_fail 38 self._times_to_fail = times_to_fail
39 self.ValidateAndMeasurePage.side_effect = self.maybeFail 39 self.ValidateAndMeasurePage.side_effect = self.maybeFail
40 40
41 def maybeFail(self, page, tab, results): 41 def maybeFail(self, page, tab, results):
42 if self._times_to_fail > 0: 42 if self._times_to_fail > 0:
43 self._times_to_fail = self._times_to_fail - 1 43 self._times_to_fail = self._times_to_fail - 1
44 raise Exception('Deliberate exception') 44 raise Exception('Deliberate exception')
45 45
46 46
47 class FakePage(gpu_test_base.PageBase): 47 class FakePage(gpu_test_base.PageBase):
48 def __init__(self, benchmark, name, manager_mock=None): 48 def __init__(self, benchmark, name, manager_mock=None,
49 shared_page_state_class=gpu_test_base.FakeGpuSharedPageState):
49 super(FakePage, self).__init__( 50 super(FakePage, self).__init__(
50 name=name, 51 name=name,
51 url='http://nonexistentserver.com/' + name, 52 url='http://nonexistentserver.com/' + name,
52 page_set=benchmark.GetFakeStorySet(), 53 page_set=benchmark.GetFakeStorySet(),
53 shared_page_state_class=gpu_test_base.FakeGpuSharedPageState, 54 shared_page_state_class=shared_page_state_class,
54 expectations=benchmark.GetExpectations()) 55 expectations=benchmark.GetExpectations())
55 if manager_mock == None: 56 if manager_mock == None:
56 self.RunNavigateSteps = mock.Mock() 57 self.RunNavigateSteps = mock.Mock()
57 self.RunPageInteractions = mock.Mock() 58 self.RunPageInteractions = mock.Mock()
58 else: 59 else:
59 self.RunNavigateSteps = manager_mock.RunNavigateSteps 60 self.RunNavigateSteps = manager_mock.RunNavigateSteps
60 self.RunPageInteractions = manager_mock.RunPageInteractions 61 self.RunPageInteractions = manager_mock.RunPageInteractions
61 62
62 63
64 class SharedPageStateWhichTimesOutNTimes(gpu_test_base.FakeGpuSharedPageState):
65 # This has to be a class variable because it's not possible to
66 # interpose on SharedPageState's constructor.
67 times_to_fail = 1
68
69 def DidRunStory(self, results): #pylint: disable=arguments-differ
70 if SharedPageStateWhichTimesOutNTimes.times_to_fail > 0:
71 SharedPageStateWhichTimesOutNTimes.times_to_fail = \
72 SharedPageStateWhichTimesOutNTimes.times_to_fail - 1
73 super(SharedPageStateWhichTimesOutNTimes, self).DidRunStory(
74 results, force_timeout_exception=True)
75 super(SharedPageStateWhichTimesOutNTimes, self).DidRunStory(
76 self, results)
77
78
63 class FakeTest(gpu_test_base.TestBase): 79 class FakeTest(gpu_test_base.TestBase):
64 def __init__(self, 80 def __init__(self,
65 times_to_fail_test=0, 81 times_to_fail_test=0,
66 manager_mock=None, 82 manager_mock=None,
67 max_failures=None): 83 max_failures=None):
68 super(FakeTest, self).__init__(max_failures) 84 super(FakeTest, self).__init__(max_failures)
69 self._fake_pages = [] 85 self._fake_pages = []
70 self._fake_story_set = story_set_module.StorySet() 86 self._fake_story_set = story_set_module.StorySet()
71 self._created_story_set = False 87 self._created_story_set = False
72 validator_mock = manager_mock.validator if manager_mock else None 88 validator_mock = manager_mock.validator if manager_mock else None
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 126
111 class CrashingPage(FakePage): 127 class CrashingPage(FakePage):
112 def __init__(self, benchmark, name, manager_mock=None): 128 def __init__(self, benchmark, name, manager_mock=None):
113 super(CrashingPage, self).__init__(benchmark, name, 129 super(CrashingPage, self).__init__(benchmark, name,
114 manager_mock=manager_mock) 130 manager_mock=manager_mock)
115 self.RunNavigateSteps.side_effect = ( 131 self.RunNavigateSteps.side_effect = (
116 exceptions.DevtoolsTargetCrashException(None)) 132 exceptions.DevtoolsTargetCrashException(None))
117 133
118 134
119 class PageWhichFailsNTimes(FakePage): 135 class PageWhichFailsNTimes(FakePage):
120 def __init__(self, benchmark, name, times_to_fail, manager_mock=None): 136 def __init__(self, benchmark, name, times_to_fail, manager_mock=None,
121 super(PageWhichFailsNTimes, self).__init__(benchmark, name, 137 shared_page_state_class=gpu_test_base.FakeGpuSharedPageState):
122 manager_mock=manager_mock) 138 super(PageWhichFailsNTimes, self).__init__(
139 benchmark, name, manager_mock=manager_mock,
140 shared_page_state_class=shared_page_state_class)
123 self._times_to_fail = times_to_fail 141 self._times_to_fail = times_to_fail
124 self.RunNavigateSteps.side_effect = self.maybeFail 142 self.RunNavigateSteps.side_effect = self.maybeFail
125 143
126 def maybeFail(self, action_runner): 144 def maybeFail(self, action_runner):
127 if self._times_to_fail > 0: 145 if self._times_to_fail > 0:
128 self._times_to_fail = self._times_to_fail - 1 146 self._times_to_fail = self._times_to_fail - 1
129 raise Exception('Deliberate exception') 147 raise Exception('Deliberate exception')
130 148
131 class PageRunExecutionTest(unittest.TestCase): 149 class PageRunExecutionTest(unittest.TestCase):
132 def testNoGarbageCollectionCalls(self): 150 def testNoGarbageCollectionCalls(self):
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 mock.call.validator.WillNavigateToPage( 329 mock.call.validator.WillNavigateToPage(
312 page, mock.ANY), 330 page, mock.ANY),
313 mock.call.page.RunNavigateSteps(mock.ANY), 331 mock.call.page.RunNavigateSteps(mock.ANY),
314 mock.call.validator.DidNavigateToPage( 332 mock.call.validator.DidNavigateToPage(
315 page, mock.ANY), 333 page, mock.ANY),
316 mock.call.page.RunPageInteractions(mock.ANY), 334 mock.call.page.RunPageInteractions(mock.ANY),
317 mock.call.validator.ValidateAndMeasurePage( 335 mock.call.validator.ValidateAndMeasurePage(
318 page, mock.ANY, mock.ANY)] 336 page, mock.ANY, mock.ANY)]
319 self.assertTrue(manager.mock_calls == expected) 337 self.assertTrue(manager.mock_calls == expected)
320 338
339 def testFlakyFailureInDidRunStory(self):
340 manager = mock.Mock()
341 test, finder_options = self.setupTest(manager_mock=manager)
342 page = PageWhichFailsNTimes(
343 test, 'page1', 1, manager_mock=manager.page,
344 shared_page_state_class=SharedPageStateWhichTimesOutNTimes)
345 SharedPageStateWhichTimesOutNTimes.times_to_fail = 1
346 test.AddFakePage(page)
347 test.GetExpectations().Flaky('page1')
348 self.assertEqual(test.Run(finder_options), 0,
349 'Test should run with no errors')
350 expected = [mock.call.validator.WillNavigateToPage(
351 page, mock.ANY),
352 mock.call.page.RunNavigateSteps(mock.ANY),
353 mock.call.validator.WillNavigateToPage(
354 page, mock.ANY),
355 mock.call.page.RunNavigateSteps(mock.ANY),
356 mock.call.validator.DidNavigateToPage(
357 page, mock.ANY),
358 mock.call.page.RunPageInteractions(mock.ANY),
359 mock.call.validator.ValidateAndMeasurePage(
360 page, mock.ANY, mock.ANY)]
361 self.assertTrue(manager.mock_calls == expected)
362
321 def testFlakyPageExceedingNumRetries(self): 363 def testFlakyPageExceedingNumRetries(self):
322 manager = mock.Mock() 364 manager = mock.Mock()
323 test, finder_options = self.setupTest(manager_mock=manager) 365 test, finder_options = self.setupTest(manager_mock=manager)
324 page = PageWhichFailsNTimes(test, 'page1', 2, manager_mock=manager.page) 366 page = PageWhichFailsNTimes(test, 'page1', 2, manager_mock=manager.page)
325 test.AddFakePage(page) 367 test.AddFakePage(page)
326 test.GetExpectations().Flaky('page1', max_num_retries=1) 368 test.GetExpectations().Flaky('page1', max_num_retries=1)
327 self.assertNotEqual(test.Run(finder_options), 0, 369 self.assertNotEqual(test.Run(finder_options), 0,
328 'Test should fail') 370 'Test should fail')
329 expected = [mock.call.validator.WillNavigateToPage( 371 expected = [mock.call.validator.WillNavigateToPage(
330 page, mock.ANY), 372 page, mock.ANY),
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 mock.call.page2.RunNavigateSteps(mock.ANY), 430 mock.call.page2.RunNavigateSteps(mock.ANY),
389 mock.call.validator.WillNavigateToPage( 431 mock.call.validator.WillNavigateToPage(
390 page2, mock.ANY), 432 page2, mock.ANY),
391 mock.call.page2.RunNavigateSteps(mock.ANY), 433 mock.call.page2.RunNavigateSteps(mock.ANY),
392 mock.call.validator.DidNavigateToPage( 434 mock.call.validator.DidNavigateToPage(
393 page2, mock.ANY), 435 page2, mock.ANY),
394 mock.call.page2.RunPageInteractions(mock.ANY), 436 mock.call.page2.RunPageInteractions(mock.ANY),
395 mock.call.validator.ValidateAndMeasurePage( 437 mock.call.validator.ValidateAndMeasurePage(
396 page2, mock.ANY, mock.ANY)] 438 page2, mock.ANY, mock.ANY)]
397 self.assertTrue(manager.mock_calls == expected) 439 self.assertTrue(manager.mock_calls == expected)
OLDNEW
« content/test/gpu/gpu_tests/gpu_test_base.py ('K') | « content/test/gpu/gpu_tests/gpu_test_base.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698