1- import asyncio
1+ import anyio
22import json
33import pytest
44import httpx
@@ -69,7 +69,7 @@ async def test_transfer_id_already_used(websocket_client: WebSocketTestClient):
6969
7070# # Override the timeout for the test to make it fail quickly
7171# async def mock_wait_for_client_connected(self):
72- # await asyncio .sleep(1.0) # Short delay
72+ # await anyio .sleep(1.0) # Short delay
7373# raise asyncio.TimeoutError("Mocked timeout")
7474
7575# from lib.transfer import FileTransfer
@@ -95,32 +95,32 @@ async def test_receiver_disconnects(test_client: httpx.AsyncClient, websocket_cl
9595 async def sender ():
9696 with pytest .raises (ConnectionClosedError , match = "Transfer was interrupted by the receiver" ):
9797 async with websocket_client .websocket_connect (f"/send/{ uid } " ) as ws :
98- await asyncio .sleep (0.1 )
98+ await anyio .sleep (0.1 )
9999
100100 await ws .send_json ({
101101 'file_name' : file_metadata .name ,
102102 'file_size' : file_metadata .size ,
103103 'file_type' : file_metadata .type
104104 })
105- await asyncio .sleep (1.0 ) # Allow receiver to connect
105+ await anyio .sleep (1.0 ) # Allow receiver to connect
106106
107107 response = await ws .recv ()
108- await asyncio .sleep (0.1 )
108+ await anyio .sleep (0.1 )
109109 assert response == "Go for file chunks"
110110
111111 chunks = [file_content [i :i + 4096 ] for i in range (0 , len (file_content ), 4096 )]
112112 for chunk in chunks :
113113 await ws .send_bytes (chunk )
114- await asyncio .sleep (0.1 )
114+ await anyio .sleep (0.1 )
115115
116- await asyncio .sleep (2.0 )
116+ await anyio .sleep (2.0 )
117117
118118 async def receiver ():
119- await asyncio .sleep (1.0 )
119+ await anyio .sleep (1.0 )
120120 headers = {'Accept' : '*/*' }
121121
122122 async with test_client .stream ("GET" , f"/{ uid } ?download=true" , headers = headers ) as response :
123- await asyncio .sleep (0.1 )
123+ await anyio .sleep (0.1 )
124124
125125 response .raise_for_status ()
126126 i = 0
@@ -131,11 +131,11 @@ async def receiver():
131131 i += 1
132132 if i >= 5 :
133133 raise ClientDisconnect ("Simulated disconnect" )
134- await asyncio .sleep (0.025 )
134+ await anyio .sleep (0.025 )
135135
136- t1 = asyncio . create_task ( asyncio . wait_for ( sender (), timeout = 15 ))
137- t2 = asyncio . create_task ( asyncio . wait_for ( receiver (), timeout = 15 ) )
138- await asyncio . gather ( t1 , t2 )
136+ async with anyio . create_task_group () as tg :
137+ tg . start_soon ( sender )
138+ tg . start_soon ( receiver )
139139
140140
141141@pytest .mark .anyio
@@ -146,18 +146,18 @@ async def test_prefetcher_request(test_client: httpx.AsyncClient, websocket_clie
146146
147147 # Create a dummy transfer to get metadata
148148 async with websocket_client .websocket_connect (f"/send/{ uid } " ) as ws :
149- await asyncio .sleep (0.1 )
149+ await anyio .sleep (0.1 )
150150
151151 await ws .send_json ({
152152 'file_name' : file_metadata .name ,
153153 'file_size' : file_metadata .size ,
154154 'file_type' : file_metadata .type
155155 })
156- await asyncio .sleep (1.0 )
156+ await anyio .sleep (1.0 )
157157
158158 headers = {'User-Agent' : 'facebookexternalhit/1.1' }
159159 response = await test_client .get (f"/{ uid } " , headers = headers )
160- await asyncio .sleep (0.1 )
160+ await anyio .sleep (0.1 )
161161
162162 assert response .status_code == 200
163163 assert "text/html" in response .headers ['content-type' ]
@@ -172,18 +172,18 @@ async def test_browser_download_page(test_client: httpx.AsyncClient, websocket_c
172172 _ , file_metadata = generate_test_file ()
173173
174174 async with websocket_client .websocket_connect (f"/send/{ uid } " ) as ws :
175- await asyncio .sleep (0.1 )
175+ await anyio .sleep (0.1 )
176176
177177 await ws .send_json ({
178178 'file_name' : file_metadata .name ,
179179 'file_size' : file_metadata .size ,
180180 'file_type' : file_metadata .type
181181 })
182- await asyncio .sleep (1.0 )
182+ await anyio .sleep (1.0 )
183183
184184 headers = {'User-Agent' : 'Mozilla/5.0' }
185185 response = await test_client .get (f"/{ uid } " , headers = headers )
186- await asyncio .sleep (0.1 )
186+ await anyio .sleep (0.1 )
187187
188188 assert response .status_code == 200
189189 assert "text/html" in response .headers ['content-type' ]
0 commit comments