From 048ea1585b4e1b89ef1f547844869ef9a74accd8 Mon Sep 17 00:00:00 2001
From: log
Date: Thu, 09 Jul 2026 18:36:34 +0800
Subject: [PATCH] fix: abort akshare history after repeated failures

---
 tests/test_data_update_v2.py |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/tests/test_data_update_v2.py b/tests/test_data_update_v2.py
index 31df51a..4e02a65 100644
--- a/tests/test_data_update_v2.py
+++ b/tests/test_data_update_v2.py
@@ -107,6 +107,35 @@
             ],
         )
 
+    def test_akshare_history_failures_abort_before_full_stock_pool(self):
+        class FakeAkShare:
+            def __init__(self):
+                self.history_calls = 0
+
+            def stock_info_a_code_name(self):
+                return pd.DataFrame(
+                    [
+                        {"code": f"{index:06d}", "name": f"测试{index}"}
+                        for index in range(1, 21)
+                    ]
+                )
+
+            def stock_zh_a_hist(self, **kwargs):
+                self.history_calls += 1
+                raise ConnectionError(
+                    "Remote end closed connection without response"
+                )
+
+        fake_ak = FakeAkShare()
+
+        with patch.dict(sys.modules, {"akshare": fake_ak}):
+            result = data_update_v2.fetch_real_stock_data_from_akshare_only(
+                n_stocks=20, days=10, max_consecutive_failures=3
+            )
+
+        self.assertIsNone(result)
+        self.assertEqual(fake_ak.history_calls, 3)
+
     def test_convert_baostock_history_matches_existing_schema(self):
         raw = pd.DataFrame(
             [

--
Gitblit v1.8.0