Skip to content

test(terminalwidget): 终端单元测试迁移到自研实现 - #598

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/terminalwidgetfrom
Kakueeen:test/terminalwidget-unit-tests
Nov 20, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/terminalwidgetfrom
Kakueeen:test/terminalwidget-unit-tests

Conversation

@Kakueeen

@Kakueeen Kakueeen commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

三方终端替换为自研 DTerminal 组件后,原先依赖 qtermwidget、TerminalDisplay 的 ut_termwidget、ut_termwidgetpage、ut_mainwindow 三个用例文件被排除出构建。本次将它们改为调用自研接口并重新启用,同时清理测试侧遗留的三方用例开关与残留头文件。

启用后暴露出两处测试基建缺陷,一并修复:UT_MainWindow_Test 用 deleteLater 释放的窗口会泄漏到后续套件,其集中析构挤占事件循环,使后续用例的定时器错过等待窗口;UT_Dbusmanager_Test 延迟析构 DBusManager,与 QtDBus 工作线程的消息投递并发时会导致进程崩溃。前者在 TearDown 主动排空延迟删除队列,后者改为确定性析构。

验证:全量单元测试 427 项全部通过(启用前 281 项),连续两轮无失败;另外实测将 3rdparty 目录整体移出后,全新 configure + 全量重编 + 全量单测仍全部通过。

Log:终端单元测试由三方接口迁移到自研实现,并修复两处测试基建缺陷。
PMS:TASK-398539

Summary by Sourcery

将终端单元测试迁移至自研 DTerminal 实现,清理第三方测试残留,并提升测试资源清理与 DBus 生命周期管理的稳定性。

Bug Fixes:

  • 修复主窗口测试中延迟删除窗口未及时清理导致的资源泄漏和后续测试事件循环受阻问题。
  • 修复 DBusManager 延迟析构与 QtDBus 消息投递并发引发的测试进程崩溃问题。

Enhancements:

  • 将终端相关单元测试迁移至自研 DTerminal 接口并重新纳入测试构建。
  • 清理测试侧遗留的第三方终端测试开关、头文件及相关依赖。

Tests:

  • 恢复并适配终端组件、终端页面和主窗口单元测试以覆盖自研终端实现。

三方终端替换为自研 DTerminal 组件后,原先依赖 qtermwidget、TerminalDisplay
的 ut_termwidget、ut_termwidgetpage、ut_mainwindow 三个用例文件被排除出构建。
本次将它们改为调用自研接口并重新启用,同时清理测试侧遗留的三方用例开关与
残留头文件。

启用后暴露出两处测试基建缺陷,一并修复:UT_MainWindow_Test 用 deleteLater
释放的窗口会泄漏到后续套件,其集中析构挤占事件循环,使后续用例的定时器错过
等待窗口;UT_Dbusmanager_Test 延迟析构 DBusManager,与 QtDBus 工作线程的
消息投递并发时会导致进程崩溃。前者在 TearDown 主动排空延迟删除队列,后者
改为确定性析构。

全量单元测试 427 项全部通过(启用前 281 项),连续两轮无失败。

Log:终端单元测试由三方接口迁移到自研实现,并修复两处测试基建缺陷。
PMS:TASK-398539
@sourcery-ai

sourcery-ai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Reviewer's Guide

Configuration

Re-enable the terminal-related test sources by removing the exclusion filter from the test source list.

  • tests/CMakeLists.txt L92 (removed lines)

Tests

Migrate MainWindow tests from third-party terminal interfaces to DTerminalView and add deterministic cleanup and behavior assertions for deferred windows, paste, zoom, and select-all.

  • tests/src/main/ut_mainwindow_test.cpp L1226-1231, L1239-1253, L1499-1511 (+5 small edits)

Use deterministic destruction for DBusManager to avoid deferred cleanup racing with DBus message delivery.

  • tests/src/main/ut_dbusmanager_test.cpp L21-24

Remove the obsolete third-party terminal test switches and their unused export header.

  • tests/src/3rdparty/terminalwidget/lib/qtermwidget_export.h (deleted)
  • tests/src/common/ut_defines.h L72 (removed lines)

Remove obsolete third-party terminal includes from the TermWidget test.

  • tests/src/views/ut_termwidget_test.cpp L10 (removed lines)

Update TermWidgetPage tests to observe DTerminal cursor, blinking, scroll, and codec behavior through the self-developed terminal interfaces.

  • tests/src/views/ut_termwidgetpage_test.cpp L114-125, L306-317, L432-440 (+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 1 issue

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

## Individual Comments

### Comment 1
<location path="tests/src/main/ut_mainwindow_test.cpp" line_range="114" />
<code_context>
+    // 若改用 deleteLater(),析构会被推迟到后续用例/套件的事件循环里,
+    // 与 DBus 线程的消息投递并发,曾导致进程 SIGSEGV。
+    delete m_pDbusManager;
 }

 #ifdef UT_DBUSMANAGER_TEST
</code_context>
<issue_to_address>
**Unrelated objects are deleted early**

When an unrelated object has a pending DeferredDelete event when this fixture tears down, `sendPostedEvents(nullptr, QEvent::DeferredDelete)` drains deferred deletions for every object in the application, not only windows created by this fixture. A pending deletion owned by another fixture or shared service is therefore processed during this teardown, changing its lifetime and potentially invalidating state still used by later tests.

Drain deferred deletes only for windows created by this fixture, or track and clean up those windows explicitly.
</issue_to_address>

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

// 部分用例以 deleteLater() 释放自建窗口,这里主动排空延迟删除队列,
// 避免窗口泄漏到后续用例/后续套件(泄漏会拖慢其它用例的定时器与事件处理)
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
}

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 objects are deleted early

When an unrelated object has a pending DeferredDelete event when this fixture tears down, sendPostedEvents(nullptr, QEvent::DeferredDelete) drains deferred deletions for every object in the application, not only windows created by this fixture. A pending deletion owned by another fixture or shared service is therefore processed during this teardown, changing its lifetime and potentially invalidating state still used by later tests.

Drain deferred deletes only for windows created by this fixture, or track and clean up those windows explicitly.

Prompt for AI agents
In `tests/src/main/ut_mainwindow_test.cpp` at line 114:

**Unrelated objects are deleted early**

When an unrelated object has a pending DeferredDelete event when this fixture tears down, `sendPostedEvents(nullptr, QEvent::DeferredDelete)` drains deferred deletions for every object in the application, not only windows created by this fixture. A pending deletion owned by another fixture or shared service is therefore processed during this teardown, changing its lifetime and potentially invalidating state still used by later tests.

Drain deferred deletes only for windows created by this fixture, or track and clean up those windows explicitly.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@Kakueeen

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit 318daeb into linuxdeepin:develop/terminalwidget Nov 20, 2026
13 of 14 checks passed
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