test: try reduce flakiness of test_ssl (#2735)
test: replace badssl.com with google.com/generate_204 in SSL test Switch to a more reliable HTTPS endpoint and add retry logic with exponential backoff to reduce flaky test failures.
This commit is contained in:
+17
-10
@@ -1,4 +1,3 @@
|
|||||||
import socket
|
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -8,14 +7,25 @@ from . import test_projects, utils
|
|||||||
project_with_ssl_tests = test_projects.new_c_project(
|
project_with_ssl_tests = test_projects.new_c_project(
|
||||||
setup_py_add=textwrap.dedent(
|
setup_py_add=textwrap.dedent(
|
||||||
r"""
|
r"""
|
||||||
import ssl
|
import ssl, time, urllib.request, urllib.error
|
||||||
|
|
||||||
from urllib.request import urlopen
|
def check_https(context=None):
|
||||||
|
# google hosts this endpoint that returns a 204 No Content, it's used for
|
||||||
|
# connectivity checks in Android & Chrome
|
||||||
|
url = "https://google.com/generate_204"
|
||||||
|
|
||||||
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
|
for i in range(5):
|
||||||
# badssl.com is a HTTPS test server that can be used to test SSL connections
|
try:
|
||||||
data = urlopen("https://tls-v1-2.badssl.com", context=context)
|
urllib.request.urlopen(url, context=context, timeout=5)
|
||||||
data = urlopen("https://tls-v1-2.badssl.com")
|
return
|
||||||
|
except (OSError, urllib.error.URLError) as e:
|
||||||
|
print(f"Attempt {i+1}: Could not connect to {url}: {e}")
|
||||||
|
time.sleep(2 ** i) # Backoff: 1s, 2s, 4s, 8s...
|
||||||
|
|
||||||
|
raise ConnectionError(f"Could not connect to {url} after retries.")
|
||||||
|
|
||||||
|
check_https()
|
||||||
|
check_https(context=ssl.SSLContext(ssl.PROTOCOL_TLSv1_2))
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -28,9 +38,6 @@ def test(tmp_path):
|
|||||||
project_dir = tmp_path / "project"
|
project_dir = tmp_path / "project"
|
||||||
project_with_ssl_tests.generate(project_dir)
|
project_with_ssl_tests.generate(project_dir)
|
||||||
|
|
||||||
# warm up connection
|
|
||||||
socket.getaddrinfo("tls-v1-2.badssl.com", 443)
|
|
||||||
|
|
||||||
actual_wheels = utils.cibuildwheel_run(project_dir)
|
actual_wheels = utils.cibuildwheel_run(project_dir)
|
||||||
|
|
||||||
expected_wheels = utils.expected_wheels("spam", "0.1.0")
|
expected_wheels = utils.expected_wheels("spam", "0.1.0")
|
||||||
|
|||||||
Reference in New Issue
Block a user