Repository navigation
test: isolate PerformanceMonitor UT from runner log rules #752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,19 +17,22 @@ | |
| * - 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 <gtest/gtest.h> | ||
| #include "stubext.h" | ||
|
|
||
| #include "performancemonitor.h" | ||
|
|
||
| #include <QCoreApplication> | ||
| #include <QDateTime> | ||
| #include <QDebug> | ||
| #include <QLoggingCategory> | ||
| #include <QStringList> | ||
| #include <QVector> | ||
|
|
||
| namespace { | ||
|
|
||
|
|
@@ -64,6 +67,13 @@ | |
| 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 @@ | |
|
|
||
| void TearDown() override | ||
| { | ||
| // 先恢复运行环境自带的日志规则(无则清空回到进程默认),再恢复默认 | ||
| // handler,避免中间窗口 debug/info 直接打到 stderr | ||
| QLoggingCategory::setFilterRules(QString::fromLatin1(qgetenv("QT_LOGGING_RULES"))); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Runner log filters are not restored When the runner provides multiple logging rules separated by semicolons, Convert semicolons to newlines before passing the saved environment value to Prompt for AI agentsIn `tests/common2/test_performancemonitor.cpp` at line 95:
**Runner log filters are not restored**
When the runner provides multiple logging rules separated by semicolons, `QLoggingCategory::setFilterRules` receives the runner’s semicolon-separated `QT_LOGGING_RULES` value as-is; the rules are not restored as separate filters, so later tests run without the debug/info suppression and emit excess logs.
Convert semicolons to newlines before passing the saved environment value to `setFilterRules`. |
||
| qInstallMessageHandler(nullptr); // 恢复默认 handler | ||
| g_capturedLogs = nullptr; | ||
| stub.clear(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium · Unrelated logs reach the platform cap
When an unrelated category emits debug or info messages while a PerformanceMonitor test runs,
setFilterRulesreplaces the runner’s rules and drops its*.debug=falseand*.info=falsefilters, so other categories use Qt’s enabled defaults and their messages reach the test log, potentially hitting the platform cap.Preserve the runner’s filters when adding the
org.deepin.editoroverrides.Prompt for AI agents