question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TestClient on mac takes exactly 30s for every .get call

See original GitHub issue

I previously opened this issue at FastAPI: https://github.com/tiangolo/fastapi/issues/1567, but traced the problem to Starlette.

Details

On Mac with new install of Starlette, every call to TestClient.get() takes exactly 30s to complete. The response, when it arrives, is correct.

Environment

  • OS: Macbook Pro 10.13.6
  • Starlette version: 0.13.4
  • Python version: 3.6

Example

Copy and paste the example from the Starlette docs https://www.starlette.io/testclient/ into a brand new venv:

from starlette.responses import HTMLResponse
from starlette.testclient import TestClient


async def app(scope, receive, send):
    assert scope['type'] == 'http'
    response = HTMLResponse('<html><body>Hello, world!</body></html>')
    await response(scope, receive, send)


def test_app():
    client = TestClient(app)
    response = client.get('/')
    assert response.status_code == 200

Alternatively, you can clone the repo at https://github.com/charlesbaynham/fastapi_mwe and use the requirements.txt to duplicate my environment. Running python test_starlette.py takes 30s. This repo also contains a cProfile of the test which looks like this:

image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

15reactions
mcmxcommented, Nov 5, 2020

In my case, each test takes around 7.5 seconds to run, by @erewok comment, I took a look at TestClient which defines base_url as ‘http://testserver’ by default, which is not resolvable of course.

So I changed the call to TestClient for this:

client = TestClient(app, base_url='http://localhost')

Now the test runs in 0.3s, this is running MacOS 10.14.6 in a MacBook Pro, Python 3.8.0.

Hope this helps some else.

1reaction
charlesbaynhamcommented, Jun 22, 2020

After some digging I tracked it down to the Search Domains setting of my local network, this was set to “local”, removing that immediately fixed the issue.

That sounds familiar, I’ve been messing around with OpenWRT recently. Thanks for your help and sorry to have wasted your time!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Test Client - Starlette
The test client allows you to make requests against your ASGI application, ... Set headers for each request separately response = client.get("/", ...
Read more >
Make and receive phone calls on Mac or iPad - Apple Support
On your Mac, open the FaceTime app, choose FaceTime > Settings (or Preferences), then select Calls From iPhone.
Read more >
Save disk space with OneDrive Files On-Demand for Mac
When you turn on Files On-Demand, you'll see all your files in Mac Finder and get ... appear as online-only files, which don't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found