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

Side by Side Diff: build/android/pylib/base_test_sharder.py

Issue 11232037: Retry tests on other bots if the device is unresponsive/offline (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: small fixes Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 5
6 import android_commands
6 import logging 7 import logging
7 import multiprocessing 8 import multiprocessing
8 9
9 from test_result import TestResults 10 from test_result import TestResults
10 11
11 12
12 def _ShardedTestRunnable(test): 13 def _ShardedTestRunnable(test):
13 """Standalone function needed by multiprocessing.Pool.""" 14 """Standalone function needed by multiprocessing.Pool."""
14 log_format = '[' + test.device + '] # %(asctime)-15s: %(message)s' 15 log_format = '[' + test.device + '] # %(asctime)-15s: %(message)s'
15 if logging.getLogger().handlers: 16 if logging.getLogger().handlers:
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 Returns: 72 Returns:
72 A TestResults object. 73 A TestResults object.
73 """ 74 """
74 logging.warning('*' * 80) 75 logging.warning('*' * 80)
75 logging.warning('Sharding in ' + str(len(self.attached_devices)) + 76 logging.warning('Sharding in ' + str(len(self.attached_devices)) +
76 ' devices.') 77 ' devices.')
77 logging.warning('Note that the output is not synchronized.') 78 logging.warning('Note that the output is not synchronized.')
78 logging.warning('Look for the "Final result" banner in the end.') 79 logging.warning('Look for the "Final result" banner in the end.')
79 logging.warning('*' * 80) 80 logging.warning('*' * 80)
80 final_results = TestResults() 81 final_results = TestResults()
81 for retry in xrange(self.retries): 82 rounds = self.retries
83 retry = 0
84 while retry < rounds:
82 logging.warning('Try %d of %d', retry + 1, self.retries) 85 logging.warning('Try %d of %d', retry + 1, self.retries)
83 self.SetupSharding(self.tests) 86 self.SetupSharding(self.tests)
84 test_runners = [] 87 test_runners = []
85 for index, device in enumerate(self.attached_devices): 88 for index, device in enumerate(self.attached_devices):
86 logging.warning('*' * 80) 89 logging.warning('*' * 80)
87 logging.warning('Creating shard %d for %s', index, device) 90 logging.warning('Creating shard %d for %s', index, device)
88 logging.warning('*' * 80) 91 logging.warning('*' * 80)
89 test_runner = self.CreateShardedTestRunner(device, index) 92 test_runner = self.CreateShardedTestRunner(device, index)
90 test_runners += [test_runner] 93 test_runners += [test_runner]
91 logging.warning('Starting...') 94 logging.warning('Starting...')
92 pool = multiprocessing.Pool(len(self.attached_devices), 95 pool = multiprocessing.Pool(len(self.attached_devices),
93 SetTestsContainer, 96 SetTestsContainer,
94 [BaseTestSharder.tests_container]) 97 [BaseTestSharder.tests_container])
95 # map can't handle KeyboardInterrupt exception. It's a python bug. 98 # map can't handle KeyboardInterrupt exception. It's a python bug.
96 # So use map_async instead. 99 # So use map_async instead.
97 async_results = pool.map_async(_ShardedTestRunnable, test_runners) 100 async_results = pool.map_async(_ShardedTestRunnable, test_runners)
98 results_lists = async_results.get(999999) 101 results_lists = async_results.get(999999)
102
103 if (TestResults.HasDeviceExcept(results_lists) and
104 retry == rounds - 1):
105 rounds += 1
bulach 2012/10/23 09:30:56 hmm.. this may never finish: if we keep getting de
yongsheng 2012/10/23 12:58:14 oh, yes. So what if retry equals to rounds - 1? t
yongsheng 2012/10/23 13:08:35 if one device raise exception, then it's excluded
bulach 2012/10/23 15:01:53 oh, sorry, I think the current semantics (before y
yongsheng 2012/10/24 01:41:52 my only concern is that if there are failures(due
bulach 2012/10/24 10:43:49 I think that'd be fine, at least it's deterministi
106
99 test_results = TestResults.FromTestResults(results_lists) 107 test_results = TestResults.FromTestResults(results_lists)
100 if retry == self.retries - 1: 108 # Re-check the attached devices for some devices may
109 # become offline
110 self.attached_devices = android_commands.GetAttachedDevices()
bulach 2012/10/23 09:30:56 nice! for extra safety, maybe we could do somethin
yongsheng 2012/10/23 12:58:14 great improvement. thanks. I'll follow your sugges
111 if (retry == rounds - 1 or
112 len(self.attached_devices) == 0):
101 all_passed = final_results.ok + test_results.ok 113 all_passed = final_results.ok + test_results.ok
102 final_results = test_results 114 final_results = test_results
103 final_results.ok = all_passed 115 final_results.ok = all_passed
104 break 116 break
105 else: 117 else:
106 final_results.ok += test_results.ok 118 final_results.ok += test_results.ok
107 self.tests = [] 119 self.tests = []
108 for t in test_results.GetAllBroken(): 120 for t in test_results.GetAllBroken():
109 self.tests += [t.name] 121 self.tests += [t.name]
110 if not self.tests: 122 if not self.tests:
111 break 123 break
112 self.OnTestsCompleted(test_runners, final_results) 124 self.OnTestsCompleted(test_runners, final_results)
113 return final_results 125 return final_results
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698