55from httpx import AsyncClient , ASGITransport
66from app .main import app
77
8- BASE_URL = "http://localhost:8000"
9-
108@pytest .mark .asyncio
11- async def test_sync_and_persistence ():
9+ async def test_sync_and_persistence (server ):
1210 # 1. Create Session
13- async with AsyncClient (base_url = BASE_URL ) as ac :
11+ async with AsyncClient (base_url = server ) as ac :
1412 res = await ac .post ("/sessions" , json = {
1513 "candidateName" : "Test Candidate" ,
1614 "candidateEmail" : "test@example.com" ,
@@ -31,7 +29,7 @@ async def on_session_updated(data):
3129 if not future_session_update .done ():
3230 future_session_update .set_result (data )
3331
34- await sio_a .connect (BASE_URL , socketio_path = '/socket.io' )
32+ await sio_a .connect (server , socketio_path = '/socket.io' )
3533 await sio_a .emit ('join_room' , {
3634 'roomId' : session_id ,
3735 'user' : {'id' : 'user_a' , 'name' : 'Interviewer' , 'role' : 'interviewer' }
@@ -67,7 +65,7 @@ async def on_code_change(data):
6765 if not future_code_sync .done ():
6866 future_code_sync .set_result (data )
6967
70- await sio_b .connect (BASE_URL , socketio_path = '/socket.io' )
68+ await sio_b .connect (server , socketio_path = '/socket.io' )
7169 await sio_b .emit ('join_room' , {
7270 'roomId' : session_id ,
7371 'user' : {'id' : 'user_b' , 'name' : 'Candidate' , 'role' : 'candidate' }
@@ -80,9 +78,9 @@ async def on_code_change(data):
8078 await sio_b .disconnect ()
8179
8280@pytest .mark .asyncio
83- async def test_user_presence ():
81+ async def test_user_presence (server ):
8482 # 1. Create Session
85- async with AsyncClient (base_url = BASE_URL ) as ac :
83+ async with AsyncClient (base_url = server ) as ac :
8684 res = await ac .post ("/sessions" , json = {
8785 "candidateName" : "Test Candidate" ,
8886 "candidateEmail" : "test@example.com" ,
@@ -102,14 +100,14 @@ async def on_room_users_b(data):
102100 future_users_b .set_result (data )
103101
104102 # A joins
105- await sio_a .connect (BASE_URL , socketio_path = '/socket.io' )
103+ await sio_a .connect (server , socketio_path = '/socket.io' )
106104 await sio_a .emit ('join_room' , {
107105 'roomId' : session_id ,
108106 'user' : {'id' : 'user_a' , 'name' : 'Interviewer' , 'role' : 'interviewer' }
109107 })
110108
111109 # B joins
112- await sio_b .connect (BASE_URL , socketio_path = '/socket.io' )
110+ await sio_b .connect (server , socketio_path = '/socket.io' )
113111 await sio_b .emit ('join_room' , {
114112 'roomId' : session_id ,
115113 'user' : {'id' : 'user_b' , 'name' : 'Candidate' , 'role' : 'candidate' }
@@ -123,7 +121,7 @@ async def on_room_users_b(data):
123121 future_users_b_leave = asyncio .Future ()
124122 @sio_b .on ('room_users' )
125123 async def on_room_users_b_leave (data ):
126- if not future_users_b_leave .done ():
124+ if len ( data [ 'users' ]) == 1 and not future_users_b_leave .done ():
127125 future_users_b_leave .set_result (data )
128126
129127 await sio_a .emit ('leave_room' , {'roomId' : session_id , 'userId' : 'user_a' })
@@ -137,9 +135,9 @@ async def on_room_users_b_leave(data):
137135 await sio_b .disconnect ()
138136
139137@pytest .mark .asyncio
140- async def test_whiteboard_sync ():
138+ async def test_whiteboard_sync (server ):
141139 # 1. Create Session
142- async with AsyncClient (base_url = BASE_URL ) as ac :
140+ async with AsyncClient (base_url = server ) as ac :
143141 res = await ac .post ("/sessions" , json = {
144142 "candidateName" : "Test Candidate" ,
145143 "candidateEmail" : "test@example.com" ,
@@ -159,13 +157,13 @@ async def on_whiteboard_update(data):
159157 future_wb_update .set_result (data )
160158
161159 # Connect both
162- await sio_a .connect (BASE_URL , socketio_path = '/socket.io' )
160+ await sio_a .connect (server , socketio_path = '/socket.io' )
163161 await sio_a .emit ('join_room' , {
164162 'roomId' : session_id ,
165163 'user' : {'id' : 'user_a' , 'name' : 'Interviewer' , 'role' : 'interviewer' }
166164 })
167165
168- await sio_b .connect (BASE_URL , socketio_path = '/socket.io' )
166+ await sio_b .connect (server , socketio_path = '/socket.io' )
169167 await sio_b .emit ('join_room' , {
170168 'roomId' : session_id ,
171169 'user' : {'id' : 'user_b' , 'name' : 'Candidate' , 'role' : 'candidate' }
0 commit comments