Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions deepin-devicemanager/src/GenerateDevice/LoadInfoThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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); // 执行了命令加载
}


Expand Down Expand Up @@ -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
Expand Down
Loading