refactor: 复用持久设备工作线程 (#110)

This commit is contained in:
chengma
2026-08-10 18:00:38 +08:00
parent 553659208a
commit 70cedc34d4
11 changed files with 563 additions and 149 deletions
+30
View File
@@ -1153,6 +1153,36 @@ class PDDTaskPageEventTest(unittest.TestCase):
events.shutdown()
page.deleteLater()
def test_auto_fetch_reuses_one_fixed_worker_thread_across_cycles(self):
gateway = RecordingClaimGateway()
page = PDDTaskPage()
events = PDDTaskPageEvent(
page,
self.repository,
claim_gateway=gateway,
settings_repository=self._saved_settings(),
collect_service_factory=fake_collect_factory,
no_task_delay_ms=10,
)
page.autoFetchRequested.emit()
self.assertTrue(
wait_until(self.app, lambda: len(gateway.thread_ids) >= 2),
"自动获取没有完成两轮串行调度",
)
executor_thread = events._claim_thread
page.autoFetchRequested.emit()
self.assertTrue(wait_until(self.app, lambda: not events._claim_busy))
self.assertIs(events._claim_thread, executor_thread)
self.assertTrue(
executor_thread is not None and executor_thread.isRunning()
)
self.assertEqual(len(set(gateway.thread_ids)), 1)
events.shutdown()
self.assertFalse(executor_thread.isRunning())
page.deleteLater()
def test_new_claim_refreshes_table_before_collection_finishes(self):
gateway = RecordingClaimGateway(collect_admin_task("COL-EARLY"))
collect_started = threading.Event()