uvicorn
uvicorn copied to clipboard
Use updated headers from server state
- Closes #1618
The idea here is to use the ServerState object instead of passing the server_state.default_headers to the <protocol>.default_headers attribute.
How to test it?
- Use the same snippet provided on #1618.
You should probably add the test from the discussion so that we're sure it is ok in the future.
This said, I played a little with the test, the PR fixes the failed test, BUT, I find that as soon as the sleep is below 1s, the test fails again, any idea ?
Yeah, the on_tick function runs every second.
Ideas for testing this?
ok so just the test added will be fine I suppose: with a 1.1s sleep it should do the job, maybea add a note refering to the on_tick so we know that's a limitation and headers cannot be refreshed more that once per second because of this. Ideally on_tick should be configurable, but not too sure
This doesn't work. I've set 1-second sleep, and I got 2 seconds difference.
I tried to play with mocking the asyncio.sleep(0.1), and using time-machine package, but none work properly.
works fine on linux, I just added prints, what mac is doing ???
============================= test session starts ==============================
collecting ... collected 1 item
test_default_headers.py::test_date_headers_update
============================== 1 passed in 1.48s ===============================
Process finished with exit code 0
PASSED [100%]INFO: 127.0.0.1:42396 - "GET / HTTP/1.1" 200 OK
INFO: 127.0.0.1:42396 - "GET / HTTP/1.1" 200 OK
2022-09-15 03:08:36
2022-09-15 03:08:37
INFO: Started server process [1871053]
INFO: Waiting for application startup.
INFO: ASGI 'lifespan' protocol appears unsupported.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Shutting down
By "I got" I mean the pipeline got. 😟
The job failing is with 2 seconds diff.
can we add microseconds on the CI just to check is it possible to reproduce locally, I have no mac >_)
Why would the microseconds matter here? Also, the pipeline on mac also fails with timedelta < 1 :sweat_smile:
Why would the microseconds matter here?
It's a real question, seeing the on_tick and main_loop I don't know how that would help (nor where I should be printing it).
I was thinking maybe there could have been a rounding effect in the difference leading to having a difference of 2 instead of one, But apparently there is no microseconds set in the headers so that wont help. However removing the test is probably not a solution, would be interesting to dig further to see why macos is doing that, it's waiting for one more seconds so there's likely somethig fishy going on
However removing the test is probably not a solution, would be interesting to dig further to see why macos is doing that, it's waiting for one more seconds so there's likely somethig fishy going on
Not necessarily... As I said:
Also, the pipeline on mac also fails with timedelta < 1 :sweat_smile:
The pipeline is failing for >1 and <1 for Mac.
The pipeline is failing for >1 and <1 for Mac.
but locally it's ok ?
The pipeline is failing for >1 and <1 for Mac.
but locally it's ok ?
I don't know. I've been using Ubuntu. I'll try on the Mac later this week.
@euri10 Can you check it? It should be less flaky now.