test(markdown): fix flaky RenderThrottle leading/trailing edge case - #548
Conversation
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: 消除全量测试运行时该用例偶现失败,测试结果稳定可信。
Reviewer's guide (collapsed on small PRs)Reviewer's GuideStabilizes 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
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 无需修改,语法正确,逻辑清晰 2. 代码质量 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 无需修改,代码结构清晰,注释完整 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 无需修改,轮询循环在条件满足时提前退出,性能良好 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 无需修改,测试代码无安全风险 💡 改进建议代码示例// 本次变更已为最佳实践,无需修改
// 测试用例 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 代码审查工具自动生成 |
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/merge |
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:
Tests: