From b4c702b6820e2aff85f0d6d8c531c7048e96f4fe Mon Sep 17 00:00:00 2001 From: dengzhongyuan365-dev Date: Fri, 20 Nov 2026 23:14:52 +0800 Subject: [PATCH] fix: load device info when server is updating MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Root cause: LoadInfoThread::run() skipped data loading entirely when is_server_running returned "1", leaving DeviceManager empty 2. Fix: replace skip with polling loop (500ms interval, 30s timeout) that waits for server update to finish, then loads data normally 3. Impact: device info always loads regardless of server state; max 30s delay when server is updating, with fallback load on timeout Log: Fixed incomplete device info after reopening device manager Influence: 1. Test reopening device manager while server is updating 2. Verify device info displays completely after multiple opens 3. Test app shutdown during server update polling (no hang) fix: 服务端更新时加载设备信息 1. 根因:LoadInfoThread::run() 在 is_server_running 返回 "1" 时完全 跳过数据加载,导致 DeviceManager 为空,信息显示不全 2. 方案:将跳过改为轮询等待(500ms 间隔,30s 超时),等待服务端更新 完成后正常加载数据;超时后仍执行本地加载作为兜底 3. 影响:设备信息始终加载,不再因服务端状态跳过;服务端更新期间 最多延迟 30s,超时后降级加载 Log: 修复多次打开设备管理器后信息显示不全的问题 Influence: 1. 测试服务端更新时重新打开设备管理器 2. 验证多次打开后设备信息完整显示 3. 测试轮询等待期间关闭应用(无挂起) PMS: BUG-378099 --- .../src/GenerateDevice/LoadInfoThread.cpp | 21 +++++++++++++++---- .../src/GenerateDevice/ut_loadinfothread.cpp | 12 ++++++----- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/deepin-devicemanager/src/GenerateDevice/LoadInfoThread.cpp b/deepin-devicemanager/src/GenerateDevice/LoadInfoThread.cpp index 9efd64168..c79e9f588 100644 --- a/deepin-devicemanager/src/GenerateDevice/LoadInfoThread.cpp +++ b/deepin-devicemanager/src/GenerateDevice/LoadInfoThread.cpp @@ -62,8 +62,23 @@ void LoadInfoThread::run() qCDebug(appLog) << "LoadInfoThread::run is_server_running:" << info; // 请求后台更新信息 m_Running = true; - if (!info.toInt()) { - qCDebug(appLog) << "LoadInfoThread::run server is not running, start to get info"; + if (info.toInt()) { + qCDebug(appLog) << "LoadInfoThread::run server is running, waiting for it to finish"; + long long pollBegin = QDateTime::currentMSecsSinceEpoch(); + while (info.toInt()) { + if (QDateTime::currentMSecsSinceEpoch() - pollBegin > 30000) { + qCWarning(appLog) << "LoadInfoThread::run server still running after 30s, loading with current data as fallback"; + break; + } + usleep(500000); + DBusInterface::getInstance()->getInfo("is_server_running", info); + } + if (!info.toInt()) { + qCDebug(appLog) << "LoadInfoThread::run server finished updating, start to get info"; + } + } + { + qCDebug(appLog) << "LoadInfoThread::run start to get info"; m_Start = false; mp_ReadFilePool.getAllInfo(); mp_ReadFilePool.waitForDone(-1); @@ -120,8 +135,6 @@ void LoadInfoThread::run() m_FinishedReadFilePool = false; mp_GenerateDevicePool.generateDevice(); mp_GenerateDevicePool.waitForDone(-1); - } else { - qCDebug(appLog) << "LoadInfoThread::run server is running, do nothing"; } emit finished("finish"); diff --git a/test/deepin-devicemanager/src/GenerateDevice/ut_loadinfothread.cpp b/test/deepin-devicemanager/src/GenerateDevice/ut_loadinfothread.cpp index 18aeb1c60..19d4c5fbc 100644 --- a/test/deepin-devicemanager/src/GenerateDevice/ut_loadinfothread.cpp +++ b/test/deepin-devicemanager/src/GenerateDevice/ut_loadinfothread.cpp @@ -255,22 +255,23 @@ TEST_F(UT_LoadInfoThread, SlotFinishedReadFilePool_FreshInstance_FlagStillSet) -/// B1: server 运行(info="1") -> 跳过重载路径, 直接 emit finished +/// B1: server 运行(info="1") -> 轮询等待(超时)后仍执行加载路径 TEST_F(UT_LoadInfoThread, Run_ServerRunning_SkipsHeavyPath) { - // Arrange + // Arrange: server 运行, 轮询超时后降级加载 s_dbusInfo = "1"; + m_stub.set(ADDR(QDateTime, currentMSecsSinceEpoch), ut_qdt_now); // Act m_thread->run(); // Assert EXPECT_EQ(m_finishEmits, 1); EXPECT_EQ(m_finishMsg, "finish"); - EXPECT_TRUE(m_thread->m_Start); // 重载路径未进入, m_Start 保持 - EXPECT_FALSE(m_thread->m_Running); // run 末尾复位 - EXPECT_EQ(s_loadCmdCalls, 0); // 未执行任何命令加载 + EXPECT_FALSE(m_thread->m_Start); // 加载路径已进入(轮询超时后降级加载) + EXPECT_FALSE(m_thread->m_Running); // run 末尾复位 + EXPECT_EQ(s_loadCmdCalls, 29); // 执行了命令加载 } @@ -324,6 +325,7 @@ TEST_F(UT_LoadInfoThread, Destructor_AfterRun_NoHang) { // Arrange s_dbusInfo = "1"; + m_stub.set(ADDR(QDateTime, currentMSecsSinceEpoch), ut_qdt_now); // Act m_thread->run(); // Assert