File tree Expand file tree Collapse file tree 1 file changed +15
-11
lines changed Expand file tree Collapse file tree 1 file changed +15
-11
lines changed Original file line number Diff line number Diff line change 10
10
11
11
import pytest
12
12
import requests
13
+ from urllib3 .exceptions import MaxRetryError
13
14
14
15
from litgpt .utils import _RunIf
15
16
@@ -215,14 +216,17 @@ def run_server():
215
216
server_thread = threading .Thread (target = run_server )
216
217
server_thread .start ()
217
218
218
- # Allow time to initialize and start serving
219
- time .sleep (30 )
220
-
221
- try :
222
- response = requests .get ("http://127.0.0.1:8000" )
223
- print (response .status_code )
224
- assert response .status_code == 200 , "Server did not respond as expected."
225
- finally :
226
- if process :
227
- process .kill ()
228
- server_thread .join ()
219
+ for _ in range (30 ):
220
+ try :
221
+ response = requests .get ("http://127.0.0.1:8000" , timeout = 1 )
222
+ response_status_code = response .status_code
223
+ except (MaxRetryError , requests .exceptions .ConnectionError ):
224
+ response_status_code = - 1
225
+ if response_status_code == 200 :
226
+ break
227
+ time .sleep (1 )
228
+ assert response_status_code == 200 , "Server did not respond as expected."
229
+
230
+ if process :
231
+ process .kill ()
232
+ server_thread .join ()
You can’t perform that action at this time.
0 commit comments