Skip to content

test: isolate PerformanceMonitor UT from runner log rules - #752

Merged
pengfeixx merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:fix/ut-performancemonitor-logs
Dec 2, 2026
Merged

pengfeixx merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:fix/ut-performancemonitor-logs

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor
  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 cc549b5, 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
PMS: TASK-398635

UT 验证任务:http://10.8.12.70:18780/task?task_id=task-857329ea212e45faa79df1c122ea9f08

Summary by Sourcery

Ensure PerformanceMonitor tests remain deterministic without changing logging behavior for other test suites.

Bug Fixes:

  • Make PerformanceMonitor unit tests reliable when runner-level logging rules disable debug and info messages.

Enhancements:

  • Isolate the test fixture's logging configuration by enabling the application category during setup and restoring the ambient rules during teardown.

Tests:

  • Stabilize log-capture and timestamp-related PerformanceMonitor assertions across different test runner environments.

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 cc549b5,
   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"
   (上游 cc549b5,为避免超出平台 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
@sourcery-ai

sourcery-ai Bot commented Nov 27, 2026

Copy link
Copy Markdown

Reviewer's Guide

Tests

Make the PerformanceMonitor test fixture temporarily enable its logging categories and restore the environment’s rules afterward, so logging assertions remain deterministic under runner-wide log filters.

  • tests/common2/test_performancemonitor.cpp L70-76 (+3 small edits)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/common2/test_performancemonitor.cpp" line_range="76" />
<code_context>
+        // setFilterRules 优先级高于环境变量,夹具内显式放开 appLog,保证用例
+        // 不随运行环境的日志配置漂移;TearDown 恢复原规则。
+        QLoggingCategory::setFilterRules(QStringLiteral(
+            "org.deepin.editor.debug=true\norg.deepin.editor.info=true"));
         stub.clear();
         logs.clear();
</code_context>
<issue_to_address>
**Unrelated logs reach the platform cap**

When an unrelated category emits debug or info messages while a PerformanceMonitor test runs, `setFilterRules` replaces the runner’s rules and drops its `*.debug=false` and `*.info=false` filters, 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.editor` overrides.
</issue_to_address>

### Comment 2
<location path="tests/common2/test_performancemonitor.cpp" line_range="95" />
<code_context>
     {
+        // 先恢复运行环境自带的日志规则(无则清空回到进程默认),再恢复默认
+        // handler,避免中间窗口 debug/info 直接打到 stderr
+        QLoggingCategory::setFilterRules(QString::fromLatin1(qgetenv("QT_LOGGING_RULES")));
         qInstallMessageHandler(nullptr); // 恢复默认 handler
         g_capturedLogs = nullptr;
</code_context>
<issue_to_address>
**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`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

// setFilterRules 优先级高于环境变量,夹具内显式放开 appLog,保证用例
// 不随运行环境的日志配置漂移;TearDown 恢复原规则。
QLoggingCategory::setFilterRules(QStringLiteral(
"org.deepin.editor.debug=true\norg.deepin.editor.info=true"));

Copy link
Copy Markdown

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, setFilterRules replaces the runner’s rules and drops its *.debug=false and *.info=false filters, 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.editor overrides.

Prompt for AI agents
In `tests/common2/test_performancemonitor.cpp` at line 76:

**Unrelated logs reach the platform cap**

When an unrelated category emits debug or info messages while a PerformanceMonitor test runs, `setFilterRules` replaces the runner’s rules and drops its `*.debug=false` and `*.info=false` filters, 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.editor` overrides.

{
// 先恢复运行环境自带的日志规则(无则清空回到进程默认),再恢复默认
// handler,避免中间窗口 debug/info 直接打到 stderr
QLoggingCategory::setFilterRules(QString::fromLatin1(qgetenv("QT_LOGGING_RULES")));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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, 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.

Prompt for AI agents
In `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`.

@deepin-bot

deepin-bot Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.6.11
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #757

@deepin-bot

deepin-bot Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.6.12
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #758

@deepin-bot

deepin-bot Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.6.13
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #764

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, pengfeixx

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pengfeixx
pengfeixx merged commit d9eeae0 into linuxdeepin:master Dec 2, 2026
19 of 20 checks passed
@pengfeixx
pengfeixx deleted the fix/ut-performancemonitor-logs branch December 2, 2026 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants