-
-
Notifications
You must be signed in to change notification settings - Fork 685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
datasette.client internal requests mechanism #1000
Conversation
Needs tests and documentation. |
Codecov Report
@@ Coverage Diff @@
## main #1000 +/- ##
==========================================
+ Coverage 84.37% 84.52% +0.15%
==========================================
Files 28 28
Lines 3871 3878 +7
==========================================
+ Hits 3266 3278 +12
+ Misses 605 600 -5
Continue to review full report at Codecov.
|
I'm going to route the existing |
Almost all of the tests are passing:
|
For this failing test I'm suspicious that the AsyncClient may be persisting cookies in between requests:
|
The topic of disabling cookie persistence is discussed a little here: encode/httpx#422 (comment)
|
I'm going to switch back to having each request run through a new client. I'm worried about the impact on test performance though. I'll run a microbenchmark before and after. |
With the single client that is reused for all tests:
After switching back to this class: class DatasetteClient:
def __init__(self, ds):
self.app = ds.app()
def _fix(self, path):
if path.startswith("/"):
path = "http://localhost{}".format(path)
return path
async def get(self, path, **kwargs):
async with httpx.AsyncClient(app=self.app) as client:
return await client.get(self._fix(path), **kwargs)
async def options(self, path, **kwargs):
async with httpx.AsyncClient(app=self.app) as client:
return await client.options(self._fix(path), **kwargs)
async def head(self, path, **kwargs):
async with httpx.AsyncClient(app=self.app) as client:
return await client.head(self._fix(path), **kwargs)
async def post(self, path, **kwargs):
async with httpx.AsyncClient(app=self.app) as client:
return await client.post(self._fix(path), **kwargs)
async def put(self, path, **kwargs):
async with httpx.AsyncClient(app=self.app) as client:
return await client.put(self._fix(path), **kwargs)
async def patch(self, path, **kwargs):
async with httpx.AsyncClient(app=self.app) as client:
return await client.patch(self._fix(path), **kwargs)
async def delete(self, path, **kwargs):
async with httpx.AsyncClient(app=self.app) as client:
return await client.delete(self._fix(path), **kwargs)
async def request(self, method, path, **kwargs):
async with httpx.AsyncClient(app=self.app) as client:
return await client.request(method, self._fix(path), **kwargs) The time taken is:
That's close enough that I don't feel I need to investigate this further. |
Still need to handle these six failing tests:
|
That one is caused by Lines 90 to 95 in a168735
|
These failures are giving me a severe "how did this ever work in the first place?" vibe:
I have a fix for them, no idea why they weren't already failing though. |
This is really weird: new set of test failures that I wasn't seeing before, and those tests aren't failing on my laptop:
|
Most likely reason for those failures is that datasette/datasette/utils/testing.py Lines 116 to 125 in 402cf87
But now I'm delegating that to WEIRD that it passes on my laptop but fails in GitHub Actions CI though. |
I'm testing this with a Against the
Against the broken branch:
This is on my laptop though so both of those pass the tests. Key difference: the The non-httpx version sets |
I may need to fuss around with how the https://github.com/encode/httpx/blob/92ca4d0cc654859fc2257c492e55d8752370d427/httpx/_transports/asgi.py#L26 is relevant:
|
Here's where # ASGI scope.
scheme, host, port, full_path = url
path, _, query = full_path.partition(b"?")
scope = {
"type": "http",
"asgi": {"version": "3.0"},
"http_version": "1.1",
"method": method.decode(),
"headers": [(k.lower(), v) for (k, v) in headers],
"scheme": scheme.decode("ascii"),
"path": unquote(path.decode("ascii")),
"query_string": query,
"server": (host.decode("ascii"), port),
"client": self.client,
"root_path": self.root_path,
} Sure enough, it doesn't set the |
My I'm going to mark these tests as |
I'm going to document this in a separate issue. |
Refs #943