| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 threading | 5 import threading |
| 6 | 6 |
| 7 class TestCollection(object): | 7 class TestCollection(object): |
| 8 """A threadsafe collection of tests. | 8 """A threadsafe collection of tests. |
| 9 | 9 |
| 10 Args: | 10 Args: |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 # Check which of the two conditions triggered the signal. | 37 # Check which of the two conditions triggered the signal. |
| 38 if self._tests_in_progress == 0: | 38 if self._tests_in_progress == 0: |
| 39 return None | 39 return None |
| 40 try: | 40 try: |
| 41 return self._tests.pop(0) | 41 return self._tests.pop(0) |
| 42 except IndexError: | 42 except IndexError: |
| 43 # Another thread beat us to the available test, wait again. | 43 # Another thread beat us to the available test, wait again. |
| 44 self._item_available_or_all_done.clear() | 44 self._item_available_or_all_done.clear() |
| 45 | 45 |
| 46 def add(self, test): | 46 def add(self, test): |
| 47 """Add an test to the collection. | 47 """Add a test to the collection. |
| 48 | 48 |
| 49 Args: | 49 Args: |
| 50 test: A test to add. | 50 test: A test to add. |
| 51 """ | 51 """ |
| 52 with self._lock: | 52 with self._lock: |
| 53 self._tests.append(test) | 53 self._tests.append(test) |
| 54 self._item_available_or_all_done.set() | 54 self._item_available_or_all_done.set() |
| 55 self._tests_in_progress += 1 | 55 self._tests_in_progress += 1 |
| 56 | 56 |
| 57 def test_completed(self): | 57 def test_completed(self): |
| (...skipping 13 matching lines...) Expand all Loading... |
| 71 yield r | 71 yield r |
| 72 | 72 |
| 73 def __len__(self): | 73 def __len__(self): |
| 74 """Return the number of tests currently in the collection.""" | 74 """Return the number of tests currently in the collection.""" |
| 75 return len(self._tests) | 75 return len(self._tests) |
| 76 | 76 |
| 77 def test_names(self): | 77 def test_names(self): |
| 78 """Return a list of the names of the tests currently in the collection.""" | 78 """Return a list of the names of the tests currently in the collection.""" |
| 79 with self._lock: | 79 with self._lock: |
| 80 return list(t.test for t in self._tests) | 80 return list(t.test for t in self._tests) |
| OLD | NEW |