Skip to content

test(markdown): fix flaky RenderThrottle leading/trailing edge case - #548

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:fix/ut-renderthrottle-flaky
Aug 27, 2026
Merged

test(markdown): fix flaky RenderThrottle leading/trailing edge case#548
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:fix/ut-renderthrottle-flaky

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Make inputs back-to-back so the 300ms timer cannot fire between them, and poll for the trailing emit instead of a single fixed qWait.

输入改为背靠背同步调用,使300ms定时器不可能在输入间触发;后沿补发
改为轮询等待,替代单次固定qWait。

Log: 修复RenderThrottle单测在高负载下的时序抖动
Influence: 消除全量测试运行时该用例偶现失败,测试结果稳定可信。

Summary by Sourcery

Make the RenderThrottle timing test deterministic and reliable under heavy test-suite load.

Enhancements:

  • Stabilize the RenderThrottle leading/trailing edge unit test by making inputs synchronous and polling for the trailing render.

Tests:

  • Eliminate timing-sensitive failures in the RenderThrottle test under high-load test runs.

Make inputs back-to-back so the 300ms timer cannot fire between them,
and poll for the trailing emit instead of a single fixed qWait.

输入改为背靠背同步调用,使300ms定时器不可能在输入间触发;后沿补发
改为轮询等待,替代单次固定qWait。

Log: 修复RenderThrottle单测在高负载下的时序抖动
Influence: 消除全量测试运行时该用例偶现失败,测试结果稳定可信。
@sourcery-ai

sourcery-ai Bot commented Aug 27, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Stabilizes the RenderThrottle leading/trailing-edge unit test by making inputs synchronous and back-to-back, then polling for the trailing signal with a bounded timeout to tolerate event-loop scheduling under load.

File-Level Changes

Change Details Files
Make the leading/trailing-edge test deterministic by ensuring all inputs occur within one cooldown window.
  • Replace timed gaps between inputs with back-to-back synchronous calls.
  • Assert the leading render occurs immediately before submitting subsequent inputs.
  • Document why event-loop-driven delays can make the test flaky under load.
tests/src/editor/markdown/ut_renderthrottle.cpp
Wait robustly for the trailing render instead of relying on one fixed delay.
  • Poll in short intervals until the second signal arrives or a bounded timeout is reached.
  • Retain assertions verifying exactly two renders and the expected leading payload.
tests/src/editor/markdown/ut_renderthrottle.cpp

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 ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 100 分,大于 70 分通过阈值,代码质量符合要求。本次变更修复了 RenderThrottle 单元测试在高负载下的时序抖动问题,通过将输入改为背靠背同步调用并使用轮询等待替代固定 qWait,使测试结果稳定可信。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 无需修改,语法正确,逻辑清晰


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 无需修改,代码结构清晰,注释完整


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 无需修改,轮询循环在条件满足时提前退出,性能良好


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 无需修改,测试代码无安全风险


💡 改进建议代码示例

// 本次变更已为最佳实践,无需修改
// 测试用例 MultipleInputs_Within300ms_LeadingAndTrailing 的修改要点:
//
// 1. 输入改为背靠背同步调用(移除 qWait 间隔),确保 300ms 定时器
//    不可能在输入间触发,从而保证 b/c 确定性地落在冷却窗口内
// 2. 第一个输入后添加 ASSERT_EQ(spy.count(), 1) 验证前沿渲染
// 3. 后沿补发改为轮询等待(for 循环 + qWait(20)),替代单次固定 qWait(350)
//    在事件循环被饿死时仍能可靠捕获定时器投递

TEST_F(UT_RenderThrottle, MultipleInputs_Within300ms_LeadingAndTrailing)
{
    RenderThrottle t;
    t.setReady(true);
    QSignalSpy spy(&t, &RenderThrottle::renderRequested);

    t.noteContent(QStringLiteral("a"));   // 前沿:立即渲染 "a",进入 300ms 冷却
    ASSERT_EQ(spy.count(), 1);
    t.noteContent(QStringLiteral("b"));   // 冷却期内累积
    t.noteContent(QStringLiteral("c"));   // pending 更新为最新 "c"

    // 轮询等待后沿补发(单次 qWait 在事件循环被饿死时可能错过定时器投递)
    for (int i = 0; i < 250 && spy.count() < 2; ++i)
        QTest::qWait(20);

    ASSERT_EQ(spy.count(), 2);                       // 前沿 "a" + 后沿 "c"
    EXPECT_EQ(spy.takeFirst().at(0).toString(), QStringLiteral("a"));
    EXPECT_EQ(spy.takeFirst().at(0).toString(), QStringLiteral("c"));
}

本报告由 AI 代码审查工具自动生成

@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

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit 0694d62 into linuxdeepin:master Aug 27, 2026
17 checks passed
@pengfeixx
pengfeixx deleted the fix/ut-renderthrottle-flaky branch August 27, 2026 03:11
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