Fall back to Node download mirror

This commit is contained in:
王鹏
2026-10-10 11:33:22 +08:00
parent 0363e6295a
commit 4156fa6a8f
2 changed files with 121 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ from deploy_tool.installer import (
MYSQL_INSTALLER_SHA256,
MYSQL_INSTALLER_URL,
NODE_DIST_BASE,
NODE_DIST_MIRROR_BASE,
build_mysql_installer_command,
build_mysql_server_install_command,
build_mysql_service_start_script,
@@ -290,6 +291,42 @@ class InstallerTests(unittest.TestCase):
self.assertEqual(insecure_fallback.call_count, 3)
self.assertTrue(any("跳过 HTTPS 证书校验" in message for message in messages))
def test_node_download_switches_to_mirror_when_official_connection_is_closed(self):
version = "16.20.2"
directory = f"node-v{version}-win-x64"
archive_name = f"{directory}.zip"
archive_buffer = io.BytesIO()
with zipfile.ZipFile(archive_buffer, "w") as archive:
archive.writestr(f"{directory}/node.exe", "node")
archive.writestr(f"{directory}/npm.cmd", "npm")
archive_bytes = archive_buffer.getvalue()
checksum = hashlib.sha256(archive_bytes).hexdigest()
index_bytes = json.dumps(
[{"version": f"v{version}", "lts": "Gallium", "files": ["win-x64-zip"]}]
).encode("utf-8")
requested_urls = []
def opener(url, timeout):
requested_urls.append(url)
if url.startswith(NODE_DIST_BASE):
raise ConnectionResetError("remote end closed connection")
self.assertTrue(url.startswith(NODE_DIST_MIRROR_BASE))
if url.endswith("index.json"):
return io.BytesIO(index_bytes)
if url.endswith("SHASUMS256.txt"):
return io.BytesIO(f"{checksum} {archive_name}\n".encode("ascii"))
return io.BytesIO(archive_bytes)
with tempfile.TemporaryDirectory() as tmp:
messages = []
node, npm, installed_version = install_node(("16",), messages.append, Path(tmp), opener)
self.assertEqual(installed_version, version)
self.assertTrue(node.exists())
self.assertTrue(npm.exists())
self.assertTrue(any(url.startswith(NODE_DIST_MIRROR_BASE) for url in requested_urls))
self.assertTrue(any("切换国内镜像" in message for message in messages))
def test_builds_unattended_mysql_msi_install_command(self):
command = build_mysql_installer_command(Path("mysql-installer.msi"), Path("mysql-install.log"))