enh(test): robustness for ut case tfs_test.cpp#34485
Conversation
Summary of ChangesHello @kailixu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on improving the robustness of the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request enhances the robustness of the 05_MultiDisk unit test by removing assumptions about the disk allocation order from tfsAllocDisk. The introduction of the rootArr array to hold disk paths is a good refactoring that improves code clarity. The overall changes make the test less brittle and more reliable. I've included a suggestion to further improve the test's maintainability by reducing code duplication.
| code = tfsAllocDisk(pTfs, 0, "test", &did); | ||
| EXPECT_EQ(code, 0); | ||
| EXPECT_EQ(did.id, 0); | ||
| EXPECT_EQ(0 <= did.id && did.id <= 1, true); | ||
| int32_t lastId = did.id; | ||
| EXPECT_EQ(did.level, 0); | ||
| path = tfsGetDiskPath(pTfs, did); | ||
| EXPECT_STREQ(path, root00); | ||
| EXPECT_STREQ(path, rootArr[0][did.id]); | ||
|
|
||
| code = tfsAllocDisk(pTfs, 0, "test", &did); | ||
| EXPECT_EQ(code, 0); | ||
| EXPECT_EQ(did.id, 1); | ||
| EXPECT_EQ(0 <= did.id && did.id <= 1, true); | ||
| EXPECT_EQ((lastId + 1) % 2, did.id); | ||
| lastId = did.id; | ||
| EXPECT_EQ(did.level, 0); | ||
| path = tfsGetDiskPath(pTfs, did); | ||
| EXPECT_STREQ(path, root01); | ||
| EXPECT_STREQ(path, rootArr[0][did.id]); | ||
|
|
||
| code = tfsAllocDisk(pTfs, 0, "test", &did); | ||
| EXPECT_EQ(code, 0); | ||
| EXPECT_EQ(did.id, 0); | ||
| EXPECT_EQ(0 <= did.id && did.id <= 1, true); | ||
| EXPECT_EQ((lastId + 1) % 2, did.id); | ||
| lastId = did.id; | ||
| EXPECT_EQ(did.level, 0); | ||
| path = tfsGetDiskPath(pTfs, did); | ||
| EXPECT_STREQ(path, root00); | ||
| EXPECT_STREQ(path, rootArr[0][did.id]); | ||
|
|
||
| code = tfsAllocDisk(pTfs, 0, "test", &did); | ||
| EXPECT_EQ(code, 0); | ||
| EXPECT_EQ(did.id, 1); | ||
| EXPECT_EQ(0 <= did.id && did.id <= 1, true); | ||
| EXPECT_EQ((lastId + 1) % 2, did.id); | ||
| lastId = did.id; | ||
| EXPECT_EQ(did.level, 0); | ||
| path = tfsGetDiskPath(pTfs, did); | ||
| EXPECT_STREQ(path, root01); | ||
| EXPECT_STREQ(path, rootArr[0][did.id]); | ||
|
|
||
| code = tfsAllocDisk(pTfs, 0, "test", &did); | ||
| EXPECT_EQ(code, 0); | ||
| EXPECT_EQ(did.id, 0); | ||
| EXPECT_EQ(0 <= did.id && did.id <= 1, true); | ||
| EXPECT_EQ((lastId + 1) % 2, did.id); | ||
| lastId = did.id; | ||
| EXPECT_EQ(did.level, 0); | ||
| path = tfsGetDiskPath(pTfs, did); | ||
| EXPECT_STREQ(path, root00); | ||
| EXPECT_STREQ(path, rootArr[0][did.id]); | ||
|
|
||
| code = tfsAllocDisk(pTfs, 0, "test", &did); | ||
| EXPECT_EQ(code, 0); | ||
| EXPECT_EQ(did.id, 1); | ||
| EXPECT_EQ(0 <= did.id && did.id <= 1, true); | ||
| EXPECT_EQ((lastId + 1) % 2, did.id); | ||
| lastId = did.id; | ||
| EXPECT_EQ(did.level, 0); | ||
| path = tfsGetDiskPath(pTfs, did); | ||
| EXPECT_STREQ(path, root01); | ||
| EXPECT_STREQ(path, rootArr[0][did.id]); |
There was a problem hiding this comment.
This block of tests for tfsAllocDisk on level 0 contains a lot of repetition. You can refactor it using a loop to improve readability and maintainability. This also provides an opportunity to use the more idiomatic EXPECT_TRUE for boolean checks.
The same refactoring principle can be applied to the subsequent test blocks for level 1 and level 2.
code = tfsAllocDisk(pTfs, 0, "test", &did);
EXPECT_EQ(code, 0);
EXPECT_TRUE(0 <= did.id && did.id <= 1);
int32_t lastId = did.id;
EXPECT_EQ(did.level, 0);
path = tfsGetDiskPath(pTfs, did);
EXPECT_STREQ(path, rootArr[0][did.id]);
for (int i = 0; i < 5; ++i) {
code = tfsAllocDisk(pTfs, 0, "test", &did);
EXPECT_EQ(code, 0);
EXPECT_TRUE(0 <= did.id && did.id <= 1);
EXPECT_EQ((lastId + 1) % 2, did.id);
lastId = did.id;
EXPECT_EQ(did.level, 0);
path = tfsGetDiskPath(pTfs, did);
EXPECT_STREQ(path, rootArr[0][did.id]);
}
Description
Issue(s)
Checklist
Please check the items in the checklist if applicable.