5
5
import httpx
6
6
import pytest
7
7
8
- from tests .utils import run_server
8
+ from tests .utils import assert_signal , run_server
9
9
from uvicorn import Server
10
10
from uvicorn .config import Config
11
11
@@ -31,8 +31,8 @@ async def wait_app(scope, receive, send):
31
31
32
32
config = Config (app = wait_app , reload = False , port = unused_tcp_port , timeout_graceful_shutdown = 1 )
33
33
server : Server
34
- async with run_server ( config ) as server :
35
- async with httpx .AsyncClient () as client :
34
+ with assert_signal ( signal . SIGINT ) :
35
+ async with run_server ( config ) as server , httpx .AsyncClient () as client :
36
36
req = asyncio .create_task (client .get (f"http://127.0.0.1:{ unused_tcp_port } " ))
37
37
await asyncio .sleep (0.1 ) # ensure next tick
38
38
server .handle_exit (sig = signal .SIGINT , frame = None ) # exit
@@ -64,8 +64,8 @@ async def forever_app(scope, receive, send):
64
64
65
65
config = Config (app = forever_app , reload = False , port = unused_tcp_port , timeout_graceful_shutdown = 1 )
66
66
server : Server
67
- async with run_server ( config ) as server :
68
- async with httpx .AsyncClient () as client :
67
+ with assert_signal ( signal . SIGINT ) :
68
+ async with run_server ( config ) as server , httpx .AsyncClient () as client :
69
69
req = asyncio .create_task (client .get (f"http://127.0.0.1:{ unused_tcp_port } " ))
70
70
await asyncio .sleep (0.1 ) # next tick
71
71
# trigger exit, this request should time out in ~1 sec
@@ -94,10 +94,10 @@ async def app(scope, receive, send):
94
94
95
95
config = Config (app = app , reload = False , port = unused_tcp_port , timeout_graceful_shutdown = 1 )
96
96
server : Server
97
- async with run_server ( config ) as server :
98
- # exit and ensure we do not accept more requests
99
- server . handle_exit ( sig = signal . SIGINT , frame = None )
100
- await asyncio . sleep ( 0.1 ) # next tick
101
- async with httpx . AsyncClient () as client :
97
+ with assert_signal ( signal . SIGINT ) :
98
+ async with run_server ( config ) as server , httpx . AsyncClient () as client :
99
+ # exit and ensure we do not accept more requests
100
+ server . handle_exit ( sig = signal . SIGINT , frame = None )
101
+ await asyncio . sleep ( 0.1 ) # next tick
102
102
with pytest .raises (httpx .ConnectError ):
103
103
await client .get (f"http://127.0.0.1:{ unused_tcp_port } " )
0 commit comments