1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/webrtc/trunk/build/android/pylib/sharded_tests_queue.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,35 @@ 1.4 +# Copyright (c) 2012 The Chromium Authors. All rights reserved. 1.5 +# Use of this source code is governed by a BSD-style license that can be 1.6 +# found in the LICENSE file. 1.7 + 1.8 + 1.9 +"""A module that contains a queue for running sharded tests.""" 1.10 + 1.11 +import multiprocessing 1.12 + 1.13 + 1.14 +class ShardedTestsQueue(object): 1.15 + """A queue for managing pending tests across different runners. 1.16 + 1.17 + This class should only be used when sharding. 1.18 + 1.19 + Attributes: 1.20 + num_devices: an integer; the number of attached Android devices. 1.21 + tests: a list of tests to be run. 1.22 + tests_queue: if sharding, a JoinableQueue object that holds tests from 1.23 + |tests|. Otherwise, a list holding tests. 1.24 + results_queue: a Queue object to hold TestResults objects. 1.25 + """ 1.26 + _STOP_SENTINEL = 'STOP' # sentinel value for iter() 1.27 + 1.28 + def __init__(self, num_devices, tests): 1.29 + self.num_devices = num_devices 1.30 + self.tests_queue = multiprocessing.Queue() 1.31 + for test in tests: 1.32 + self.tests_queue.put(test) 1.33 + for _ in xrange(self.num_devices): 1.34 + self.tests_queue.put(ShardedTestsQueue._STOP_SENTINEL) 1.35 + 1.36 + def __iter__(self): 1.37 + """Returns an iterator with the test cases.""" 1.38 + return iter(self.tests_queue.get, ShardedTestsQueue._STOP_SENTINEL)