Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangb committed Jun 23, 2022
1 parent bcec47d commit c9ac227
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tests/middleware/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ async def homepage(request):

@pytest.mark.anyio
async def test_background_tasks_client_disconnect() -> None:
# test for https://github.com/encode/starlette/issues/1438
container: List[str] = []

disconnected = anyio.Event()
Expand Down Expand Up @@ -262,11 +263,15 @@ async def send_gen() -> AsyncGenerator[None, Message]:


def test_background_tasks(test_client_factory: Callable[[ASGIApp], TestClient]) -> None:
# test for https://github.com/encode/starlette/issues/919
container: List[str] = []

async def slow_task() -> None:
container.append("started")
await anyio.sleep(2)
# small delay to give BaseHTTPMiddleware a chance to cancel us
# this is required to make the test fail prior to fixing the issue
# so do not be surprised if you remove it and the test still passes
await anyio.sleep(0.1)
container.append("finished")

async def dispatch(
Expand Down

0 comments on commit c9ac227

Please sign in to comment.