uvicorn icon indicating copy to clipboard operation
uvicorn copied to clipboard

Use updated headers from server state

Open Kludex opened this issue 3 years ago • 12 comments

  • 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.

Kludex avatar Sep 11 '22 08:09 Kludex

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?

Kludex avatar Sep 12 '22 08:09 Kludex

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

euri10 avatar Sep 13 '22 07:09 euri10

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.

Kludex avatar Sep 14 '22 21:09 Kludex

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

euri10 avatar Sep 15 '22 03:09 euri10

By "I got" I mean the pipeline got. 😟

The job failing is with 2 seconds diff.

Kludex avatar Sep 15 '22 05:09 Kludex

can we add microseconds on the CI just to check is it possible to reproduce locally, I have no mac >_)

euri10 avatar Sep 15 '22 05:09 euri10

Why would the microseconds matter here? Also, the pipeline on mac also fails with timedelta < 1 :sweat_smile:

Kludex avatar Sep 17 '22 16:09 Kludex

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).

Kludex avatar Sep 17 '22 16:09 Kludex

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

euri10 avatar Sep 19 '22 06:09 euri10

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.

Kludex avatar Sep 19 '22 07:09 Kludex

The pipeline is failing for >1 and <1 for Mac.

but locally it's ok ?

euri10 avatar Sep 19 '22 07:09 euri10

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.

Kludex avatar Sep 20 '22 16:09 Kludex

@euri10 Can you check it? It should be less flaky now.

Kludex avatar Sep 24 '22 19:09 Kludex