Use newer versions of futures that adds exception tracebacks
Depends-On: I36f1241b983f6552d8bd0471e6a7485532a95a14 Change-Id: I49899019c4a1683bc6664cf0a52dcd5151b6e282
This commit is contained in:
@@ -74,13 +74,6 @@ class MakeCompletedFutureTest(test.TestCase):
|
||||
self.assertTrue(future.done())
|
||||
self.assertIs(future.result(), result)
|
||||
|
||||
def test_make_completed_future_exception(self):
|
||||
result = IOError("broken")
|
||||
future = au.make_completed_future(result, exception=True)
|
||||
self.assertTrue(future.done())
|
||||
self.assertRaises(IOError, future.result)
|
||||
self.assertIsNotNone(future.exception())
|
||||
|
||||
|
||||
class AsyncUtilsSynchronousTest(test.TestCase,
|
||||
WaitForAnyTestsMixin):
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
# under the License.
|
||||
|
||||
import functools
|
||||
import sys
|
||||
import threading
|
||||
|
||||
from concurrent import futures as _futures
|
||||
@@ -22,6 +23,7 @@ from concurrent.futures import process as _process
|
||||
from concurrent.futures import thread as _thread
|
||||
from oslo_utils import importutils
|
||||
from oslo_utils import reflection
|
||||
import six
|
||||
|
||||
greenpatcher = importutils.try_import('eventlet.patcher')
|
||||
greenpool = importutils.try_import('eventlet.greenpool')
|
||||
@@ -175,8 +177,15 @@ class _WorkItem(object):
|
||||
return
|
||||
try:
|
||||
result = self.fn(*self.args, **self.kwargs)
|
||||
except BaseException as e:
|
||||
self.future.set_exception(e)
|
||||
except BaseException:
|
||||
exc_type, exc_value, exc_tb = sys.exc_info()
|
||||
try:
|
||||
if six.PY2:
|
||||
self.future.set_exception_info(exc_value, exc_tb)
|
||||
else:
|
||||
self.future.set_exception(exc_value)
|
||||
finally:
|
||||
del(exc_type, exc_value, exc_tb)
|
||||
else:
|
||||
self.future.set_result(result)
|
||||
|
||||
|
||||
@@ -30,13 +30,10 @@ _DONE_STATES = frozenset([
|
||||
])
|
||||
|
||||
|
||||
def make_completed_future(result, exception=False):
|
||||
"""Make a future completed with a given result."""
|
||||
def make_completed_future(result):
|
||||
"""Make and return a future completed with a given result."""
|
||||
future = futures.Future()
|
||||
if exception:
|
||||
future.set_exception(result)
|
||||
else:
|
||||
future.set_result(result)
|
||||
future.set_result(result)
|
||||
return future
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user