Skip to content

Commit f770660

Browse files
committed
fixed windows tests
1 parent b78b3c4 commit f770660

4 files changed

Lines changed: 21 additions & 7 deletions

File tree

tests/test_eagain.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
import errno
88
import time
99
import select
10+
import sys
1011
from uhttp import server as uhttp_server
1112

1213

1314
class TestEAGAIN(unittest.TestCase):
1415
"""Test EAGAIN handling"""
1516

16-
PORT = 9995
17+
PORT = 9957
1718

19+
@unittest.skipIf(sys.platform == 'win32', "Windows handles non-blocking sockets differently")
1820
def test_eagain_on_read_no_data(self):
1921
"""
2022
Test EAGAIN when reading from socket with no data available.

tests/test_keepalive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def test_max_requests_limit(self):
299299
# If we get response, connection was closed and this is new connection
300300
# or server accepted one more request
301301
self.assertTrue(len(response6) == 0 or b"200 OK" in response6)
302-
except (BrokenPipeError, ConnectionResetError):
302+
except (BrokenPipeError, ConnectionResetError, ConnectionAbortedError):
303303
# Expected - connection was closed after 5 requests
304304
pass
305305

tests/test_keepalive_limits.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def test_max_requests_limit(self):
103103

104104
time.sleep(0.1)
105105

106-
except (BrokenPipeError, ConnectionResetError):
106+
except (BrokenPipeError, ConnectionResetError, ConnectionAbortedError):
107107
# Expected after max_requests reached
108108
if i == 3: # 4th request should fail
109109
break

tests/test_respond_file_race.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,23 @@
1212
import tempfile
1313
import os
1414
import select
15+
import shutil
1516
from uhttp import server as uhttp_server
1617

1718

19+
def safe_rmtree(path, retries=3):
20+
"""Remove directory tree with retry for Windows file locking"""
21+
for i in range(retries):
22+
try:
23+
shutil.rmtree(path)
24+
return
25+
except PermissionError:
26+
if i < retries - 1:
27+
time.sleep(0.2)
28+
# Last attempt - ignore errors
29+
shutil.rmtree(path, ignore_errors=True)
30+
31+
1832
class TestRespondFileRace(unittest.TestCase):
1933
"""Test race condition in respond_file with keep-alive"""
2034

@@ -71,8 +85,7 @@ def test_is_loaded_true_while_response_pending(self):
7185
finally:
7286
client_sock.close()
7387
server.close()
74-
os.remove(test_file)
75-
os.rmdir(temp_dir)
88+
safe_rmtree(temp_dir)
7689

7790
def test_process_request_returns_false_while_response_pending(self):
7891
"""
@@ -144,8 +157,7 @@ def test_process_request_returns_false_while_response_pending(self):
144157
finally:
145158
client_sock.close()
146159
server.close()
147-
os.remove(large_file)
148-
os.rmdir(temp_dir)
160+
safe_rmtree(temp_dir)
149161

150162

151163
if __name__ == '__main__':

0 commit comments

Comments
 (0)