Skip to content

Commit 3102e5b

Browse files
[async] fix windows jobs
1 parent d60be94 commit 3102e5b

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

test/unit/aio/test_ocsp.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import os
1414
import platform
1515
import ssl
16+
import sys
1617
import time
1718
from contextlib import asynccontextmanager
1819
from os import environ, path
@@ -86,8 +87,22 @@ async def _asyncio_connect(url, timeout=5):
8687
ssl=ssl.create_default_context(),
8788
ssl_handshake_timeout=timeout,
8889
)
89-
yield protocol
90-
transport.close()
90+
try:
91+
yield protocol
92+
finally:
93+
transport.close()
94+
95+
96+
@pytest.fixture(scope="module", autouse=True)
97+
def windows_event_loop_policy():
98+
"""Set Windows to use SelectorEventLoop for better network stability."""
99+
if sys.platform == "win32":
100+
policy = asyncio.WindowsSelectorEventLoopPolicy()
101+
asyncio.set_event_loop_policy(policy)
102+
yield
103+
asyncio.set_event_loop_policy(None) # Reset
104+
else:
105+
yield
91106

92107

93108
@pytest.fixture(autouse=True)
@@ -479,7 +494,10 @@ async def test_concurrent_ocsp_requests(tmpdir, session_manager):
479494
SnowflakeOCSP.clear_cache() # reset the memory cache
480495
SFOCSP(ocsp_response_cache_uri="file://" + cache_file_name)
481496

482-
target_hosts = TARGET_HOSTS * 5
497+
# Windows has lower concurrent connection limits than Linux/Mac
498+
# Use smaller multiplier to avoid WinError 64: network name is no longer available caused by RuntimeError('Event loop is closed')
499+
multiplier = 2 if sys.platform == "win32" else 5
500+
target_hosts = TARGET_HOSTS * multiplier
483501
await asyncio.gather(
484502
*[
485503
_validate_certs_using_ocsp(hostname, cache_file_name, session_manager)

0 commit comments

Comments
 (0)