|
6 | 6 | import threading
|
7 | 7 | import datetime
|
8 | 8 | from io import BytesIO
|
| 9 | +import subprocess |
| 10 | +import sys |
9 | 11 | import time
|
10 | 12 | import typing # noqa: F401
|
11 | 13 | import unicodedata
|
12 | 14 | import unittest
|
13 | 15 |
|
14 |
| -from tornado.escape import utf8, native_str |
| 16 | +from tornado.escape import utf8, native_str, to_unicode |
15 | 17 | from tornado import gen
|
16 | 18 | from tornado.httpclient import (
|
17 | 19 | HTTPRequest,
|
@@ -676,6 +678,35 @@ def test_sync_client_error(self):
|
676 | 678 | self.assertEqual(assertion.exception.code, 404)
|
677 | 679 |
|
678 | 680 |
|
| 681 | +class SyncHTTPClientSubprocessTest(unittest.TestCase): |
| 682 | + def test_destructor_log(self): |
| 683 | + # Regression test for |
| 684 | + # https://github.com/tornadoweb/tornado/issues/2539 |
| 685 | + # |
| 686 | + # In the past, the following program would log an |
| 687 | + # "inconsistent AsyncHTTPClient cache" error from a destructor |
| 688 | + # when the process is shutting down. The shutdown process is |
| 689 | + # subtle and I don't fully understand it; the failure does not |
| 690 | + # manifest if that lambda isn't there or is a simpler object |
| 691 | + # like an int (nor does it manifest in the tornado test suite |
| 692 | + # as a whole, which is why we use this subprocess). |
| 693 | + proc = subprocess.run( |
| 694 | + [ |
| 695 | + sys.executable, |
| 696 | + "-c", |
| 697 | + "from tornado.httpclient import HTTPClient; f = lambda: None; c = HTTPClient()", |
| 698 | + ], |
| 699 | + stdout=subprocess.PIPE, |
| 700 | + stderr=subprocess.STDOUT, |
| 701 | + check=True, |
| 702 | + ) |
| 703 | + if proc.stdout: |
| 704 | + print("STDOUT:") |
| 705 | + print(to_unicode(proc.stdout)) |
| 706 | + if proc.stdout: |
| 707 | + self.fail("subprocess produced unexpected output") |
| 708 | + |
| 709 | + |
679 | 710 | class HTTPRequestTestCase(unittest.TestCase):
|
680 | 711 | def test_headers(self):
|
681 | 712 | request = HTTPRequest("http://example.com", headers={"foo": "bar"})
|
|
0 commit comments