test: add unit tests for session, discover and phone modules - #766
Conversation
Reviewer's GuideAdds ~108 new unit tests to increase coverage for the session core protocol (ProtoClient/ProtoServer/ProtoEndpoint, CooperationCore/Discover), and phone GUI VNC components (VncViewer, VNCRecvThread/VNCSendWorker, ScreenMirroringWindow/LockScreenWidget), wiring them into the coop and coop_gui test executables and extending includes as needed. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Several tests rely on shared singletons (e.g., DiscoverController::instance()) and mutate internal state; to avoid cross-test interference or flakiness, consider encapsulating state reset into a helper and ensuring all relevant fields (including any added later) are consistently restored for each test.
- The VNCRecvThread tests depend on QThread::msleep-based timing; if these become unstable on slower CI, consider introducing a more deterministic mechanism (e.g., injecting a test hook or using a short loop with a timeout that waits for a state flag) instead of fixed sleeps.
- parseDeviceJson("not a json") is tested in both discover_extra_test and cooperationcore_test; you could consolidate this case in one place to reduce duplication and keep future behavior changes easier to maintain.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Several tests rely on shared singletons (e.g., DiscoverController::instance()) and mutate internal state; to avoid cross-test interference or flakiness, consider encapsulating state reset into a helper and ensuring all relevant fields (including any added later) are consistently restored for each test.
- The VNCRecvThread tests depend on QThread::msleep-based timing; if these become unstable on slower CI, consider introducing a more deterministic mechanism (e.g., injecting a test hook or using a short loop with a timeout that waits for a state flag) instead of fixed sleeps.
- parseDeviceJson("not a json") is tested in both discover_extra_test and cooperationcore_test; you could consolidate this case in one place to reduce duplication and keep future behavior changes easier to maintain.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
25d8365 to
6aeb5ab
Compare
Add tests for session/proto (59 tests), discover controller (13 tests) and phone GUI (36 tests). Coverage improved across 3 modules. 为 session、discover 和 phone 模块补充单元测试,新增约 108 个测试用例, session 覆盖率提升至 40%,phone 提升至 65%,discover 补充数据操作覆盖。 Log: 补充 session/discover/phone 模块单元测试 Influence: 不影响现有功能,仅新增测试代码,提升模块测试覆盖率。
6aeb5ab to
c8c3e3f
Compare
deepin pr auto review★ 总体评分:85分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 --- a/tests/coop_gui/vncrecvthread_vncsendworker_test.cpp
+++ b/tests/coop_gui/vncrecvthread_vncsendworker_test.cpp
@@ -33,11 +33,9 @@ TEST(VNCRecvThreadTest, StartAndStopCycle)
{
VNCRecvThread t;
auto fakeClient = std::make_unique<rfbClient>();
- memset(fakeClient.get(), 0, sizeof(rfbClient));
t.startRun(fakeClient.get());
- // Thread starts, WaitForMessage on fake client fails quickly
- QThread::msleep(100);
+ // 直接请求停止并等待线程退出,避免固定延时导致的测试不稳定
t.stopRun();
ASSERT_TRUE(t.wait(2000)) << "Thread did not stop in time"; |
|
[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 |
Add tests for session/proto (59 tests), discover controller (13 tests) and phone GUI (36 tests). Coverage improved across 3 modules.
为 session、discover 和 phone 模块补充单元测试,新增约 108 个测试用例, session 覆盖率提升至 40%,phone 提升至 65%,discover 补充数据操作覆盖。
Log: 补充 session/discover/phone 模块单元测试
Influence: 不影响现有功能,仅新增测试代码,提升模块测试覆盖率。
Summary by Sourcery
Add new unit test suites to improve coverage for session core networking, discovery controller data handling, and phone GUI/VNC components.
Tests: