]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Test the @return_future return value assertion and move it again.
authorBen Darnell <ben@bendarnell.com>
Tue, 19 Feb 2013 04:20:16 +0000 (23:20 -0500)
committerBen Darnell <ben@bendarnell.com>
Tue, 19 Feb 2013 04:20:16 +0000 (23:20 -0500)
tornado/concurrent.py
tornado/test/concurrent_test.py

index 66cea30bef01e9efafee5fdd690fbad99ca01414..59075a3a4cf2deb932b058779a2293b83ca7fb4d 100644 (file)
@@ -26,6 +26,8 @@ try:
 except ImportError:
     futures = None
 
+class ReturnValueIgnoredError(Exception):
+    pass
 
 class DummyFuture(object):
     def __init__(self):
@@ -158,11 +160,13 @@ def return_future(f):
         with ExceptionStackContext(handle_error):
             try:
                 result = f(*args, **kwargs)
+                if result is not None:
+                    raise ReturnValueIgnoredError(
+                        "@return_future should not be used with functions "
+                        "that return values")
             except:
                 exc_info = sys.exc_info()
                 raise
-            assert result is None, ("@return_future should not be used with "
-                                    "functions that return values")
         if exc_info is not None:
             # If the initial synchronous part of f() raised an exception,
             # go ahead and raise it to the caller directly without waiting
index f0add77942c8a986ca329136fb3e5bdeb1b666ff..94ca25151d59a9660184e8e809f31fb8699dc06f 100644 (file)
@@ -19,7 +19,7 @@ import logging
 import re
 import socket
 
-from tornado.concurrent import Future, return_future
+from tornado.concurrent import Future, return_future, ReturnValueIgnoredError
 from tornado.escape import utf8, to_unicode
 from tornado import gen
 from tornado.iostream import IOStream
@@ -44,6 +44,13 @@ class ReturnFutureTest(AsyncTestCase):
     def delayed_failure(self, callback):
         self.io_loop.add_callback(lambda: 1 / 0)
 
+    @return_future
+    def return_value(self, callback):
+        # Note that the result of both running the callback and returning
+        # a value (or raising an exception) is unspecified; with current
+        # implementations the last event prior to callback resolution wins.
+        return 42
+
     def test_immediate_failure(self):
         with self.assertRaises(ZeroDivisionError):
             # The caller sees the error just like a normal function.
@@ -53,6 +60,13 @@ class ReturnFutureTest(AsyncTestCase):
         with self.assertRaises(ZeroDivisionError):
             future.result()
 
+    def test_return_value(self):
+        with self.assertRaises(ReturnValueIgnoredError):
+            self.return_value(callback=self.stop)
+        future = self.wait()
+        with self.assertRaises(ReturnValueIgnoredError):
+            future.result()
+
     def test_callback_kw(self):
         future = self.sync_future(callback=self.stop)
         future2 = self.wait()