summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChinyue Chen <chinyue@chromium.org>2012-05-30 03:56:27 (GMT)
committerGerrit <chrome-bot@google.com>2012-05-30 12:07:29 (GMT)
commit439b3afe50f1561591ebb84322c80e4f5684bd9e (patch)
tree32c389ad771ab19f984a281eaad5501ada9771f2
parent4dd0575d667b7af532d7ce3472ee9eac98a83c54 (diff)
downloadautotest-master.tar.gz
autotest-master.tar.xz
factory_StressTest: Propagate errors back from worker threads.HEADmaster
Propagate errors back from worker threads and raise error when test finished. BUG=chrome-os-partner:9743 TEST=Run factory_StressTest. Change-Id: Ic5977355fbac21192f50939a61657529c2ab6abc Reviewed-on: https://gerrit.chromium.org/gerrit/23991 Reviewed-by: Hung-Te Lin <hungte@chromium.org> Tested-by: Chinyue Chen <chinyue@chromium.org> Commit-Ready: Chinyue Chen <chinyue@chromium.org>
-rw-r--r--client/site_tests/factory_StressTest/factory_StressTest.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/client/site_tests/factory_StressTest/factory_StressTest.py b/client/site_tests/factory_StressTest/factory_StressTest.py
index 70b9abf..9bbee34 100644
--- a/client/site_tests/factory_StressTest/factory_StressTest.py
+++ b/client/site_tests/factory_StressTest/factory_StressTest.py
@@ -11,10 +11,12 @@
import datetime
+import functools
import gobject
import gtk
import logging
import os
+import Queue
import re
import subprocess
import thread
@@ -90,9 +92,25 @@ class BatteryInfo(object):
return int(self.get_value('voltage_now'))
+def propagate_exception(queue):
+ def wrap(func):
+ @functools.wraps(func)
+ def wrapper(*args, **kwargs):
+ try:
+ return func(*args, **kwargs)
+ except Exception as e:
+ queue.put(e)
+ return wrapper
+ return wrap
+
+
class factory_StressTest(test.test):
version = 2
+ # Queue for worker threads to propagate errors back.
+ _error_queue = Queue.Queue()
+
+ @propagate_exception(_error_queue)
def thread_SAT(self, seconds):
try:
result = self.job.run_test('hardware_SAT',
@@ -103,6 +121,7 @@ class factory_StressTest(test.test):
finally:
self._sat_complete = True
+ @propagate_exception(_error_queue)
def thread_Load(self, seconds):
try:
with open('/dev/null', 'w') as null:
@@ -114,6 +133,7 @@ class factory_StressTest(test.test):
finally:
self._load_complete = True
+ @propagate_exception(_error_queue)
def thread_Battery(self, seconds):
try:
battery = BatteryInfo()
@@ -129,6 +149,7 @@ class factory_StressTest(test.test):
finally:
self._battery_complete = True
+ @propagate_exception(_error_queue)
def thread_Graphics(self, times):
count = 0
try:
@@ -147,7 +168,7 @@ class factory_StressTest(test.test):
self._graphics_complete, self._battery_complete)):
with ui.gtk_lock:
gtk.main_quit()
- return True
+ return False
now = time.time()
if now <= self._start_time:
@@ -275,4 +296,8 @@ class factory_StressTest(test.test):
self._graphics_complete = True
ui.run_test_widget(self.job, vbox)
+ if not self._error_queue.empty():
+ # Raise only the first exception from worker threads.
+ raise self._error_queue.get_nowait()
+
factory.log('%s run_once finished' % self.__class__)