media/webrtc/trunk/build/android/pylib/sharded_tests_queue.py

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
michael@0 2 # Use of this source code is governed by a BSD-style license that can be
michael@0 3 # found in the LICENSE file.
michael@0 4
michael@0 5
michael@0 6 """A module that contains a queue for running sharded tests."""
michael@0 7
michael@0 8 import multiprocessing
michael@0 9
michael@0 10
michael@0 11 class ShardedTestsQueue(object):
michael@0 12 """A queue for managing pending tests across different runners.
michael@0 13
michael@0 14 This class should only be used when sharding.
michael@0 15
michael@0 16 Attributes:
michael@0 17 num_devices: an integer; the number of attached Android devices.
michael@0 18 tests: a list of tests to be run.
michael@0 19 tests_queue: if sharding, a JoinableQueue object that holds tests from
michael@0 20 |tests|. Otherwise, a list holding tests.
michael@0 21 results_queue: a Queue object to hold TestResults objects.
michael@0 22 """
michael@0 23 _STOP_SENTINEL = 'STOP' # sentinel value for iter()
michael@0 24
michael@0 25 def __init__(self, num_devices, tests):
michael@0 26 self.num_devices = num_devices
michael@0 27 self.tests_queue = multiprocessing.Queue()
michael@0 28 for test in tests:
michael@0 29 self.tests_queue.put(test)
michael@0 30 for _ in xrange(self.num_devices):
michael@0 31 self.tests_queue.put(ShardedTestsQueue._STOP_SENTINEL)
michael@0 32
michael@0 33 def __iter__(self):
michael@0 34 """Returns an iterator with the test cases."""
michael@0 35 return iter(self.tests_queue.get, ShardedTestsQueue._STOP_SENTINEL)

mercurial