Don't ignore unexpected exceptions. Have the mock report the playback errors inline with the other calls.
Signed-off-by: Jean-Marc Eurin <[email protected]> --- autotest/cli/cli_mock.py 2010-04-28 16:43:07.000000000 -0700 +++ autotest/cli/cli_mock.py 2010-04-28 16:43:07.000000000 -0700 @@ -29,7 +29,7 @@ class cli_unittest(unittest.TestCase): def setUp(self): super(cli_unittest, self).setUp() - self.god = mock.mock_god(debug=CLI_UT_DEBUG) + self.god = mock.mock_god(debug=CLI_UT_DEBUG, ut=self) self.god.stub_class_method(rpc.afe_comm, 'run') self.god.stub_function(sys, 'exit') --- autotest/cli/threads.py 2010-04-28 16:43:07.000000000 -0700 +++ autotest/cli/threads.py 2010-04-28 16:43:07.000000000 -0700 @@ -56,7 +56,7 @@ def _start_threads(self, nthreads): """ Start up threads to spawn workers. """ self.numthreads += nthreads - for i in range(nthreads): + for i in xrange(nthreads): thread = threading.Thread(target=self._new_worker) thread.setDaemon(True) self.threads.put(thread) @@ -72,7 +72,7 @@ return try: self.function(data) - except Exception: - # We don't want one function that raises to kill everything. - # TODO: Maybe keep a list of errors or something? - pass + except Exception, full_error: + # Put a catch all here. + print ('Unexpected failure in the thread calling %s: %s' % + (self.function.__name__, full_error)) --- autotest/cli/topic_common.py 2010-04-28 16:43:07.000000000 -0700 +++ autotest/cli/topic_common.py 2010-04-28 16:43:07.000000000 -0700 @@ -59,6 +59,7 @@ import socket, urllib2 from autotest_lib.cli import rpc from autotest_lib.frontend.afe.json_rpc import proxy +from autotest_lib.client.common_lib.test_utils import mock # Maps the AFE keys to printable names. @@ -479,6 +480,8 @@ what_failed=("Timed-out contacting " "the Autotest server")) raise CliError("Timed-out contacting the Autotest server") + except mock.CheckPlaybackError: + raise except Exception, full_error: # There are various exceptions throwns by JSON, # urllib & httplib, so catch them all. --- autotest/client/common_lib/test_utils/mock.py 2010-04-28 16:43:07.000000000 -0700 +++ autotest/client/common_lib/test_utils/mock.py 2010-04-28 16:43:07.000000000 -0700 @@ -1,7 +1,7 @@ __author__ = "[email protected] (Travis Miller)" -import re, collections, StringIO, sys +import re, collections, StringIO, sys, unittest class StubNotFoundError(Exception): @@ -269,7 +269,7 @@ class mock_god: NONEXISTENT_ATTRIBUTE = object() - def __init__(self, debug=False, fail_fast=True): + def __init__(self, debug=False, fail_fast=True, ut=None): """ With debug=True, all recorded method calls will be printed as they happen. @@ -282,6 +282,7 @@ self._stubs = [] self._debug = debug self._fail_fast = fail_fast + self._ut = ut def set_fail_fast(self, fail_fast): @@ -516,10 +517,15 @@ print '\nPlayback errors:' for error in self.errors: print >> sys.__stdout__, error + self._ut.fail('\n'.join(self.errors)) raise CheckPlaybackError elif len(self.recording) != 0: + errors = [] for func_call in self.recording: - print >> sys.__stdout__, "%s not called" % (func_call) + error = "%s not called" % (func_call,) + errors.append(error) + print >> sys.__stdout__, error + self._ut.fail('\n'.join(errors)) raise CheckPlaybackError self.recording.clear() _______________________________________________ Autotest mailing list [email protected] http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
