Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>
  • Loading branch information
Kludex and adriangb committed Mar 4, 2023
1 parent 35ecd94 commit 9fb398d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,11 @@ def test_lifespan_with_state(test_client_factory):
shutdown_complete = False

async def hello_world(request):
# modifications to the state should not leak across requests
assert request.state.count == 0
# modify the state, this should not leak to the lifespan or other requests
request.state.count += 1
# since state.list is a mutable object this modification _will_ leak across requests and to the lifespan
request.state.list.append(1)
return PlainTextResponse("hello, world")

Expand All @@ -687,7 +691,9 @@ async def run_startup(state):
async def run_shutdown(state):
nonlocal shutdown_complete
shutdown_complete = True
# modifications made to the state from a request do not leak to the lifespan
assert state["count"] == 0
# unless of course the request mutates a mutable object that is referenced via state
assert state["list"] == [1, 1]

app = Router(
Expand Down

0 comments on commit 9fb398d

Please sign in to comment.