From 0004230bd43e14c92b31006f93b5d2fa7df6647d Mon Sep 17 00:00:00 2001 From: xiepengfei Date: Fri, 27 Nov 2026 13:09:13 +0800 Subject: [PATCH] test: isolate PerformanceMonitor UT from runner log rules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. UT task task-1b84a8cf failed 4 PerformanceMonitorTest cases: all logsContain() assertions false and timeCalls short by 2 2. Root cause: runner script now exports QT_LOGGING_RULES="*.debug=false;*.info=false" (upstream cc549b5d, added to stay under the 256MB platform log cap); this short-circuits qCDebug/qCInfo(appLog), so messages never reach the test's capture handler and QDateTime::currentDateTime() calls inside the stream expressions no longer execute 3. Fixture now force-enables org.deepin.editor debug/info via QLoggingCategory::setFilterRules (which overrides the env rules) in SetUp, and restores the ambient QT_LOGGING_RULES in TearDown; the runner's log cap for all other suites is untouched Log: No user-facing changes Influence: 1. Run tests/test-prj-running.sh on the AT/UT cluster and verify the four PerformanceMonitorTest cases pass with the log cap in place 2. Check the UT log stays well below the 256MB platform limit 3. Confirm no Qt debug/info leakage from later suites in test_common2 after the fixture restores ambient rules test: 隔离 PerformanceMonitor UT 与运行脚本的日志规则 1. UT 任务 task-1b84a8cf 中 PerformanceMonitorTest 4 个用例失败: logsContain() 断言全为 false 且 timeCalls 少 2 次 2. 根因:运行脚本新增导出 QT_LOGGING_RULES="*.debug=false;*.info=false" (上游 cc549b5d,为避免超出平台 256MB 日志上限),该规则使 qCDebug/qCInfo(appLog) 整体短路:消息到不了测试的捕获 handler, 流表达式内的 QDateTime::currentDateTime() 调用也不再执行 3. 夹具 SetUp 用 QLoggingCategory::setFilterRules(优先级高于环境 变量)显式放开 org.deepin.editor 的 debug/info,TearDown 恢复 环境原有 QT_LOGGING_RULES;运行脚本对其他套件的日志限流不受影响 Log: 无用户可见变化 Influence: 1. 在 AT/UT 集群跑 tests/test-prj-running.sh,验证日志限流在位时 PerformanceMonitorTest 四个用例全部通过 2. 检查 UT 日志总量仍远低于平台 256MB 上限 3. 确认夹具恢复环境规则后 test_common2 后续套件无 debug/info 泄漏 PMS: TASK-398635 --- tests/common2/test_performancemonitor.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/common2/test_performancemonitor.cpp b/tests/common2/test_performancemonitor.cpp index d418be4b..cba45133 100644 --- a/tests/common2/test_performancemonitor.cpp +++ b/tests/common2/test_performancemonitor.cpp @@ -17,7 +17,9 @@ * - Constructor_NewInstance_LogsCreated → B4 * * 隔离:QDateTime::currentDateTime 全部 stub 为固定队列时间(确定性时间差), - * qInfo/qDebug 经 qInstallMessageHandler 捕获后断言(TearDown 恢复默认 handler)。 + * qInfo/qDebug 经 qInstallMessageHandler 捕获后断言(TearDown 恢复默认 handler); + * 夹具内用 setFilterRules 显式放开 appLog 的 debug/info,避免运行脚本的 + * QT_LOGGING_RULES 全局关日志导致断言失败(TearDown 恢复环境原规则)。 */ #include @@ -28,6 +30,7 @@ #include #include #include +#include #include #include @@ -64,6 +67,13 @@ class PerformanceMonitorTest : public ::testing::Test void SetUp() override { ensureApp(); + // 运行脚本会导出 QT_LOGGING_RULES="*.debug=false;*.info=false" 压日志量, + // 该规则会让 qCDebug/qCInfo(appLog) 整体短路:消息到不了捕获 handler, + // 流表达式里的 currentDateTime() 副作用也随之消失(timeCalls 少计)。 + // setFilterRules 优先级高于环境变量,夹具内显式放开 appLog,保证用例 + // 不随运行环境的日志配置漂移;TearDown 恢复原规则。 + QLoggingCategory::setFilterRules(QStringLiteral( + "org.deepin.editor.debug=true\norg.deepin.editor.info=true")); stub.clear(); logs.clear(); timeQueue.clear(); @@ -80,6 +90,9 @@ class PerformanceMonitorTest : public ::testing::Test void TearDown() override { + // 先恢复运行环境自带的日志规则(无则清空回到进程默认),再恢复默认 + // handler,避免中间窗口 debug/info 直接打到 stderr + QLoggingCategory::setFilterRules(QString::fromLatin1(qgetenv("QT_LOGGING_RULES"))); qInstallMessageHandler(nullptr); // 恢复默认 handler g_capturedLogs = nullptr; stub.clear();