]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Add a test case for async_timeout in SimpleAsyncHTTPClient.
authorCodeb Fan <codeb2cc@gmail.com>
Wed, 21 Aug 2013 07:48:55 +0000 (15:48 +0800)
committerCodeb Fan <codeb2cc@gmail.com>
Wed, 21 Aug 2013 07:48:55 +0000 (15:48 +0800)
tornado/test/simple_httpclient_test.py

index 915376a7184659a68e8b6ce1ff7c0916f8509b11..fc681898c25dba1ac42d38f940750e9a5c3f9212 100644 (file)
@@ -396,3 +396,21 @@ class HostnameMappingTestCase(AsyncHTTPTestCase):
         response = self.wait()
         response.rethrow()
         self.assertEqual(response.body, b'Hello world!')
+
+
+class HeavyloadAsyncHTTPClientTestCase(SimpleHTTPClientTestMixin, AsyncHTTPTestCase):
+    def create_client(self, **kwargs):
+        return SimpleAsyncHTTPClient(self.io_loop, force_instance=True, **kwargs)
+
+    def test_heavyload_timeout(self):
+        with closing(self.create_client(max_clients=1)) as client:
+            client.fetch(self.get_url('/trigger?wake=false'), self.stop, request_timeout=10)
+            client.fetch(self.get_url('/hello'), self.stop, async_timeout=3)
+            response = self.wait()
+
+            self.assertEqual(response.code, 599)
+            self.assertTrue(2.9 < response.request_time < 3.1, response.request_time)
+            self.assertEqual(str(response.error), "HTTP 599: Timeout")
+            self.triggers.popleft()()
+
+