Skip to content

Commit e4cde6e

Browse files
Work around the change in tornadoweb/tornado@84bb2e28
According to that commit, there is a 200 ms delay on macOS when connecting to localhost and only IPv4 is bound (which is what Tornado does). For that reason, they replaced "localhost" with "127.0.0.1" in tornado.testing.AsyncHTTPTestCase.get_url. Because wpull treats "localhost" and "127.0.0.1" as different hosts, this breaks a variety of tests for different reasons (URLs getting skipped, cookies not set, etc.) when using Tornado 4.5.3. As a workaround, this commit restores the previous behaviour of using "localhost". This may incur a performance penalty during testing on some platforms.
1 parent 1f8b0b0 commit e4cde6e

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

wpull/testing/goodapp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
import os.path
88
import time
99

10-
from tornado.testing import AsyncHTTPTestCase, AsyncHTTPSTestCase
1110
from tornado.web import HTTPError
1211
import tornado.web
1312

1413
from wpull.testing.async import AsyncTestCase
14+
from wpull.testing.util import AsyncHTTPTestCase, AsyncHTTPSTestCase
1515

1616

1717
_logger = logging.getLogger(__name__)

wpull/testing/integration/base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33

44
import asyncio
55
import tornado.web
6-
from tornado.testing import AsyncHTTPSTestCase
76
import tornado.ioloop
87

98
from wpull.testing.async import AsyncTestCase
109
from wpull.testing.badapp import BadAppTestCase
1110
from wpull.testing.ftp import FTPTestCase
1211
from wpull.testing.goodapp import GoodAppTestCase
13-
from wpull.testing.util import TempDirMixin
12+
from wpull.testing.util import TempDirMixin, AsyncHTTPSTestCase
1413

1514

1615
class AppTestCase(AsyncTestCase, TempDirMixin):

wpull/testing/util.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import os
44
from tempfile import TemporaryDirectory
5+
import tornado.testing
56

67
_logger = logging.getLogger(__name__)
78

@@ -30,3 +31,22 @@ def cd_tempdir(self):
3031
yield temp_dir
3132
finally:
3233
os.chdir(original_dir)
34+
35+
36+
class GetUrlFixMixin:
37+
# A mixin to undo the change in tornado@84bb2e28 which replaces localhost with 127.0.0.1.
38+
# https://github.com/tornadoweb/tornado/commit/84bb2e285e15415bb86cbdf2326b19f0debb80fd
39+
40+
def get_url(self, *args, **kwargs):
41+
r = super().get_url(*args, **kwargs)
42+
if '//127.0.0.1:' in r:
43+
r = r.replace('127.0.0.1', 'localhost', 1)
44+
return r
45+
46+
47+
class AsyncHTTPTestCase(GetUrlFixMixin, tornado.testing.AsyncHTTPTestCase):
48+
pass
49+
50+
51+
class AsyncHTTPSTestCase(GetUrlFixMixin, tornado.testing.AsyncHTTPSTestCase):
52+
pass

0 commit comments

Comments
 (0)