+2011-02-03 Dirk Pranke <dpranke@chromium.org>
+
+ Reviewed by Kenneth Russell.
+
+ Update, resubmit change to bug 51572. I think the race that was
+ fixed in r76703 caused the hang that caused us to roll this
+ patch out before, so I'd like to try again.
+
+ https://bugs.webkit.org/show_bug.cgi?id=51572
+
+ * Scripts/webkitpy/layout_tests/layout_package/message_broker.py:
+ * Scripts/webkitpy/layout_tests/layout_package/message_broker_unittest.py:
+
2011-02-03 Daniel Cheng <dcheng@chromium.org>
Unreviewed.
def run_message_loop(self):
threads = self._threads()
+ wedged_threads = set()
# Loop through all the threads waiting for them to finish.
some_thread_is_alive = True
t = time.time()
for thread in threads:
if thread.isAlive():
+ if thread in wedged_threads:
+ continue
+
some_thread_is_alive = True
next_timeout = thread.next_timeout()
if next_timeout and t > next_timeout:
log_wedged_worker(thread.getName(), thread.id())
thread.clear_next_timeout()
+ wedged_threads.add(thread)
exception_info = thread.exception_info()
if exception_info is not None:
if some_thread_is_alive:
time.sleep(0.01)
+ if wedged_threads:
+ _log.warning("All remaining threads are wedged, bailing out.")
+
def cancel_workers(self):
threads = self._threads()
for thread in threads:
def clear_next_timeout(self):
self._next_timeout = None
+
class TestHandler(logging.Handler):
def __init__(self, astream):
logging.Handler.__init__(self)
child_thread.start()
started_msg = starting_queue.get()
stopping_queue.put(msg)
- return broker.run_message_loop()
+ res = broker.run_message_loop()
+ if msg == 'Timeout':
+ child_thread._timeout_queue.put('done')
+ child_thread.join(1.0)
+ self.assertFalse(child_thread.isAlive())
+ return res
def test_basic(self):
interrupted = self.run_one_thread('')
self.assertRaises(KeyboardInterrupt, self.run_one_thread, 'KeyboardInterrupt')
def test_timeout(self):
+ # Because the timeout shows up as a wedged thread, this also tests
+ # log_wedged_worker().
oc = outputcapture.OutputCapture()
- oc.capture_output()
+ stdout, stderr = oc.capture_output()
+ logger = message_broker._log
+ astream = array_stream.ArrayStream()
+ handler = TestHandler(astream)
+ logger.addHandler(handler)
interrupted = self.run_one_thread('Timeout')
+ stdout, stderr = oc.restore_output()
self.assertFalse(interrupted)
- oc.restore_output()
+ logger.handlers.remove(handler)
+ self.assertTrue('All remaining threads are wedged, bailing out.' in astream.get())
def test_exception(self):
self.assertRaises(ValueError, self.run_one_thread, 'Exception')
-
-class Test(unittest.TestCase):
def test_find_thread_stack_found(self):
id, stack = sys._current_frames().items()[0]
found_stack = message_broker._find_thread_stack(id)
found_stack = message_broker._find_thread_stack(0)
self.assertEqual(found_stack, None)
- def test_log_wedged_worker(self):
- oc = outputcapture.OutputCapture()
- oc.capture_output()
- logger = message_broker._log
- astream = array_stream.ArrayStream()
- handler = TestHandler(astream)
- logger.addHandler(handler)
-
- starting_queue = Queue.Queue()
- stopping_queue = Queue.Queue()
- child_thread = TestThread(starting_queue, stopping_queue)
- child_thread.start()
- msg = starting_queue.get()
-
- message_broker.log_wedged_worker(child_thread.getName(),
- child_thread.id())
- stopping_queue.put('')
- child_thread.join(timeout=1.0)
-
- self.assertFalse(astream.empty())
- self.assertFalse(child_thread.isAlive())
- oc.restore_output()
-
if __name__ == '__main__':
unittest.main()