feat: tune cmhub image timeouts
This commit is contained in:
+13
-10
@@ -490,9 +490,9 @@ class AITests(TempDirMixin, unittest.TestCase):
|
||||
self.assertEqual("1K", payload["resolution"])
|
||||
self.assertEqual("1:1", payload["aspect_ratio"])
|
||||
self.assertTrue(payload["image_base64"].startswith("data:image/jpeg;base64,"))
|
||||
self.assertEqual((3, 650), calls[0][2]["timeout"])
|
||||
self.assertEqual((3, ai.CMHUB_IMAGE_READ_TIMEOUT_SECONDS), calls[0][2]["timeout"])
|
||||
self.assertEqual("https://cdn.example.com/generated.png", downloads[0][0])
|
||||
self.assertEqual((3, 650), downloads[0][1]["timeout"])
|
||||
self.assertEqual((3, ai.CMHUB_IMAGE_READ_TIMEOUT_SECONDS), downloads[0][1]["timeout"])
|
||||
self.assertEqual(91, events[0]["metadata"]["points_balance"])
|
||||
timed_steps = [
|
||||
event for event in steps
|
||||
@@ -668,7 +668,7 @@ class AITests(TempDirMixin, unittest.TestCase):
|
||||
image_bytes, elapsed = ai._download_cmhub_image_with_retry(
|
||||
"https://cdn.example.com/generated.png",
|
||||
connect_timeout=3,
|
||||
read_timeout=650,
|
||||
read_timeout=ai.CMHUB_IMAGE_READ_TIMEOUT_SECONDS,
|
||||
on_step=steps.append,
|
||||
slow_threshold=0,
|
||||
)
|
||||
@@ -716,7 +716,10 @@ class AITests(TempDirMixin, unittest.TestCase):
|
||||
self.assertIn("--connect-timeout", args)
|
||||
self.assertEqual("3", args[args.index("--connect-timeout") + 1])
|
||||
self.assertIn("--max-time", args)
|
||||
self.assertEqual("650", args[args.index("--max-time") + 1])
|
||||
self.assertEqual(
|
||||
str(ai.CMHUB_IMAGE_READ_TIMEOUT_SECONDS),
|
||||
args[args.index("--max-time") + 1],
|
||||
)
|
||||
self.assertIn("--max-filesize", args)
|
||||
self.assertEqual(str(ai.CMHUB_IMAGE_MAX_BYTES), args[args.index("--max-filesize") + 1])
|
||||
self.assertIn("--noproxy", args)
|
||||
@@ -733,7 +736,7 @@ class AITests(TempDirMixin, unittest.TestCase):
|
||||
image_bytes = ai._download_cmhub_image(
|
||||
url,
|
||||
connect_timeout=3,
|
||||
read_timeout=650,
|
||||
read_timeout=ai.CMHUB_IMAGE_READ_TIMEOUT_SECONDS,
|
||||
use_system_proxy=False,
|
||||
download_with_curl="true",
|
||||
)
|
||||
@@ -748,7 +751,7 @@ class AITests(TempDirMixin, unittest.TestCase):
|
||||
ai._download_cmhub_image(
|
||||
"http://127.0.0.1/a.png",
|
||||
connect_timeout=3,
|
||||
read_timeout=650,
|
||||
read_timeout=ai.CMHUB_IMAGE_READ_TIMEOUT_SECONDS,
|
||||
download_with_curl="true",
|
||||
)
|
||||
run.assert_not_called()
|
||||
@@ -772,7 +775,7 @@ class AITests(TempDirMixin, unittest.TestCase):
|
||||
image_bytes = ai._download_cmhub_image(
|
||||
"https://cdn.example.com/generated.png",
|
||||
connect_timeout=3,
|
||||
read_timeout=650,
|
||||
read_timeout=ai.CMHUB_IMAGE_READ_TIMEOUT_SECONDS,
|
||||
download_with_curl="true",
|
||||
)
|
||||
|
||||
@@ -797,7 +800,7 @@ class AITests(TempDirMixin, unittest.TestCase):
|
||||
image_bytes = ai._download_cmhub_image(
|
||||
"https://cdn.example.com/generated.png",
|
||||
connect_timeout=3,
|
||||
read_timeout=650,
|
||||
read_timeout=ai.CMHUB_IMAGE_READ_TIMEOUT_SECONDS,
|
||||
download_with_curl="auto",
|
||||
)
|
||||
|
||||
@@ -821,7 +824,7 @@ class AITests(TempDirMixin, unittest.TestCase):
|
||||
image_bytes = ai._download_cmhub_image(
|
||||
"https://cdn.example.com/generated.png",
|
||||
connect_timeout=3,
|
||||
read_timeout=650,
|
||||
read_timeout=ai.CMHUB_IMAGE_READ_TIMEOUT_SECONDS,
|
||||
download_with_curl="auto",
|
||||
)
|
||||
|
||||
@@ -886,7 +889,7 @@ class AITests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assertEqual("read_timeout", raised.exception.code)
|
||||
self.assertEqual(1, len(calls))
|
||||
self.assertEqual((3, 650), calls[0][2]["timeout"])
|
||||
self.assertEqual((3, ai.CMHUB_IMAGE_READ_TIMEOUT_SECONDS), calls[0][2]["timeout"])
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
|
||||
@@ -227,6 +227,10 @@ class AppConfigTests(TempDirMixin, unittest.TestCase):
|
||||
self.assertEqual("cmhub", ai["backend"])
|
||||
self.assertEqual("cmhub", appconfig.ai_backend(config))
|
||||
self.assertEqual("", appconfig.cmhub_config(config)["base_url"])
|
||||
self.assertEqual(
|
||||
appconfig.CMHUB_CONNECT_TIMEOUT_DEFAULT,
|
||||
appconfig.cmhub_config(config)["connect_timeout"],
|
||||
)
|
||||
self.assertFalse(os.path.exists(cmhub_path))
|
||||
self.assertEqual({"api_key": ""}, appconfig.load_cmhub_config(cmhub_path))
|
||||
|
||||
@@ -244,6 +248,20 @@ class AppConfigTests(TempDirMixin, unittest.TestCase):
|
||||
self.assertEqual("cmhub", appconfig.ai_config(migrated)["backend"])
|
||||
self.assertEqual(180, appconfig.response_timeout(migrated))
|
||||
|
||||
with open(config_path, "w", encoding="utf-8") as fh:
|
||||
json.dump({"ai": {"cmhub": {"connect_timeout": 10}}}, fh)
|
||||
migrated = appconfig.load_config(config_path)
|
||||
self.assertEqual(
|
||||
appconfig.CMHUB_CONNECT_TIMEOUT_DEFAULT,
|
||||
appconfig.cmhub_config(migrated)["connect_timeout"],
|
||||
)
|
||||
|
||||
saved = appconfig.save_config(
|
||||
{"ai": {"cmhub": {"connect_timeout": 10}}},
|
||||
path=config_path,
|
||||
)
|
||||
self.assertEqual(10, appconfig.cmhub_config(saved)["connect_timeout"])
|
||||
|
||||
direct_cfg = appconfig.default_config()
|
||||
direct_cfg["ai"]["backend"] = "direct"
|
||||
self.assertEqual("direct", appconfig.ai_backend(direct_cfg))
|
||||
|
||||
+1
-1
@@ -930,7 +930,7 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
tab.image_concurrency_spin.setValue(2)
|
||||
tab.retry_spin.setValue(1)
|
||||
tab.resolution_combo.setCurrentIndex(tab.resolution_combo.findData("2k"))
|
||||
self.assertEqual("标题 600 秒 / 图片 650 秒", tab.response_timeout_label.text())
|
||||
self.assertEqual("标题 600 秒 / 图片 900 秒", tab.response_timeout_label.text())
|
||||
tab.jpg_quality_spin.setValue(86)
|
||||
tab.chrome_path_edit.setText("D:\\Chrome\\chrome.exe")
|
||||
tab.default_debug_port_spin.setValue(9300)
|
||||
|
||||
Reference in New Issue
Block a user