Skip to content

fix: decouple PerformanceMonitor UT from debug/info logging - #766

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

pengfeixx merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:fix/ut-performancemonitor-no-log-dep

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem

UT 任务 task-1b84a8cf 与 task-7d4e671d 中 PerformanceMonitorTest 4 个用例持续失败(logsContain 断言全 false、timeCalls 少计):

  • 运行脚本导出 QT_LOGGING_RULES="*.debug=false;*.info=false"(避免打满平台 256MB 日志上限),qCDebug/qCInfo(appLog) 整体短路,消息到不了测试的捕获 handler;
  • 上一次修复 d9eeae0(夹具内 setFilterRules 放开本类别)在集群上验证无效,同样失败复现。

Solution

按"用例不依赖 debug/info 输出"重构:

  1. 用例改为状态断言:新增 PerformanceMonitor::snapshot() 返回最近一次各打点时间戳;formatInitDuration/formatCloseDuration/formatOpenFileInfo 纯函数构造 GRABPOINT 消息,直接断言格式;timeCalls 计数时钟读取——任何日志配置下结果均确定;
  2. 产品加固:各打点方法只读一次时钟(调试流复用已捕获的时间戳),消除行为对日志开关的耦合;
  3. 移除测试中的 qInstallMessageHandler 捕获与 setFilterRules 干预,不再影响运行环境日志限流。

UT 验证任务:http://10.8.12.70:18780/task?task_id=task-52ae814e72634aa899fe72123a837aa0

PMS: TASK-398635

Summary by Sourcery

Make PerformanceMonitor unit tests deterministic regardless of runtime logging configuration.

Enhancements:

  • Decouple PerformanceMonitor behavior and unit-test assertions from debug/info logging settings, while reusing a single timestamp for each instrumentation point.
  • Expose timestamp snapshots and pure GRABPOINT message formatters for direct inspection and format validation.

Tests:

  • Replace logging-capture assertions and logging-rule overrides in PerformanceMonitor tests with timestamp, clock-call, and formatted-message assertions.

1. UT tasks task-1b84a8cf and task-7d4e671d failed the 4
   PerformanceMonitorTest cases: runner exports
   QT_LOGGING_RULES="*.debug=false;*.info=false", short-circuiting
   qCDebug/qCInfo(appLog); the prior setFilterRules workaround
   (d9eeae0) proved ineffective on the cluster
2. Tests now assert state instead of log text: snapshot() exposes the
   last recorded timestamps, formatXxx() pure functions build the
   GRABPOINT messages, and timeCalls counts clock reads -- all
   deterministic under any logging configuration
3. Product hardening: each monitor method now reads the clock exactly
   once (debug streams reuse the captured timestamp), so behavior no
   longer depends on whether logging is enabled

Log: No user-facing changes

Influence:
1. Run tests/test-prj-running.sh on the AT/UT cluster with the log
   cap in place and verify the four PerformanceMonitorTest cases pass
2. Verify GRABPOINT output format is unchanged (POINT-01/02/04)
   when launching with debug logging enabled manually
3. Confirm the UT log volume still stays under the 256MB platform cap

fix: PerformanceMonitor 单元测试与 debug/info 日志解耦

1. UT 任务 task-1b84a8cf、task-7d4e671d 中 PerformanceMonitorTest
   4 个用例失败:运行脚本导出 QT_LOGGING_RULES="*.debug=false;
   *.info=false" 使 qCDebug/qCInfo(appLog) 整体短路;此前
   setFilterRules 的修复(d9eeae03)在集群上证明无效
2. 用例改为状态断言:snapshot() 暴露最近一次各打点时间戳,
   formatXxx() 纯函数构造 GRABPOINT 消息,timeCalls 计数时钟
   读取次数——任何日志配置下结果均确定
3. 产品加固:各打点方法只读一次时钟(调试流复用已捕获的
   时间戳),行为不再随日志开关变化

Log: 无用户可见变化

Influence:
1. 在 AT/UT 集群带日志限流跑 tests/test-prj-running.sh,验证
   PerformanceMonitorTest 四个用例全部通过
2. 手动以 debug 日志启动应用,确认 GRABPOINT 输出格式
   (POINT-01/02/04)与改动前一致
3. 确认 UT 日志总量仍低于平台 256MB 上限

PMS: TASK-398635
@sourcery-ai

sourcery-ai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Add a read-only snapshot structure for the monitor’s most recently recorded timestamps, which the tests use to assert state independently of logging.

  • src/common/performancemonitor.h L13-23

API

Expose snapshot and pure message-formatting functions so callers and tests can inspect timestamps and verify GRABPOINT formats without capturing logs.

  • src/common/performancemonitor.h L37-45

Implementation

Reuse one captured timestamp per monitoring operation and implement the snapshot and formatting functions, decoupling recorded state and message construction from logging rules.

  • src/common/performancemonitor.cpp L88-124 (+8 small edits)

Tests

Replace log-capture and logging-rule manipulation with deterministic timestamp, clock-read-count, and formatted-message assertions.

  • tests/common2/test_performancemonitor.cpp L12-25, L96-111, L137-156 (+11 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 reviewed your changes and they look great!


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

@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 850fb13 into linuxdeepin:master Dec 2, 2026
18 of 20 checks passed
@pengfeixx
pengfeixx deleted the fix/ut-performancemonitor-no-log-dep branch December 2, 2026 09:15
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