Skip to content

Commit

Permalink
Allow for httpx API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ahopkins committed Dec 21, 2021
1 parent 31bbbd3 commit 1faebe7
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tests/test_unix_socket.py
Expand Up @@ -5,6 +5,8 @@
import subprocess
import sys

from string import ascii_lowercase

import httpcore
import httpx
import pytest
Expand All @@ -13,6 +15,9 @@
from sanic.response import text


httpx_version = tuple(
map(int, httpx.__version__.strip(ascii_lowercase).split("."))
)
pytestmark = pytest.mark.skipif(os.name != "posix", reason="UNIX only")
SOCKPATH = "/tmp/sanictest.sock"
SOCKPATH2 = "/tmp/sanictest2.sock"
Expand Down Expand Up @@ -141,7 +146,10 @@ def handler(request):

@app.listener("after_server_start")
async def client(app, loop):
transport = httpcore.AsyncConnectionPool(uds=SOCKPATH)
if httpx_version >= (0, 20):
transport = httpx.AsyncHTTPTransport(uds=SOCKPATH)
else:
transport = httpcore.AsyncConnectionPool(uds=SOCKPATH)
try:
async with httpx.AsyncClient(transport=transport) as client:
r = await client.get("http://myhost.invalid/")
Expand Down Expand Up @@ -186,7 +194,10 @@ async def test_zero_downtime():
from time import monotonic as current_time

async def client():
transport = httpcore.AsyncConnectionPool(uds=SOCKPATH)
if httpx_version >= (0, 20):
transport = httpx.AsyncHTTPTransport(uds=SOCKPATH)
else:
transport = httpcore.AsyncConnectionPool(uds=SOCKPATH)
for _ in range(40):
async with httpx.AsyncClient(transport=transport) as client:
r = await client.get("http://localhost/sleep/0.1")
Expand Down

0 comments on commit 1faebe7

Please sign in to comment.