22import time
33import uuid
44
5- from multiprocessing import Lock
6-
75import httpx
86import pytest
97import pytest_asyncio
3432)
3533
3634
37- @pytest .fixture (scope = 'session' )
38- def port_lock ():
39- """Multiprocessing lock for acquiring available ephemeral ports."""
40- return Lock ()
41-
42-
4335@pytest .fixture (scope = 'module' )
44- def notifications_server (port_lock ):
36+ def notifications_server ():
4537 """
4638 Starts a simple push notifications injesting server and yields its URL.
4739 """
48- with port_lock :
49- host = '127.0.0.1'
50- port = find_free_port ()
51- url = f'http://{ host } :{ port } '
52-
53- process = create_app_process (create_notifications_app (), host , port )
54- process .start ()
55- try :
56- wait_for_server_ready (f'{ url } /health' )
57- except TimeoutError as e :
58- process .terminate ()
59- raise e
40+ host = '127.0.0.1'
41+ port = find_free_port ()
42+ url = f'http://{ host } :{ port } '
43+
44+ process = create_app_process (create_notifications_app (), host , port )
45+ process .start ()
46+ try :
47+ wait_for_server_ready (f'{ url } /health' )
48+ except TimeoutError as e :
49+ process .terminate ()
50+ raise e
6051
6152 yield url
6253
@@ -72,25 +63,21 @@ async def notifications_client():
7263
7364
7465@pytest .fixture (scope = 'module' )
75- def agent_server (
76- port_lock ,
77- notifications_client : httpx .AsyncClient ,
78- ):
66+ def agent_server (notifications_client : httpx .AsyncClient ):
7967 """Starts a test agent server and yields its URL."""
80- with port_lock :
81- host = '127.0.0.1'
82- port = find_free_port ()
83- url = f'http://{ host } :{ port } '
68+ host = '127.0.0.1'
69+ port = find_free_port ()
70+ url = f'http://{ host } :{ port } '
8471
85- process = create_app_process (
86- create_agent_app (url , notifications_client ), host , port
87- )
88- process .start ()
89- try :
90- wait_for_server_ready (f'{ url } /v1/card' )
91- except TimeoutError as e :
92- process .terminate ()
93- raise e
72+ process = create_app_process (
73+ create_agent_app (url , notifications_client ), host , port
74+ )
75+ process .start ()
76+ try :
77+ wait_for_server_ready (f'{ url } /v1/card' )
78+ except TimeoutError as e :
79+ process .terminate ()
80+ raise e
9481
9582 yield url
9683
0 commit comments