Skip to content

enh(test): robustness for ut case tfs_test.cpp#34485

Merged
guanshengliang merged 1 commit intomainfrom
fix/TD-6579338695-main
Feb 3, 2026
Merged

enh(test): robustness for ut case tfs_test.cpp#34485
guanshengliang merged 1 commit intomainfrom
fix/TD-6579338695-main

Conversation

@kailixu
Copy link
Copy Markdown
Contributor

@kailixu kailixu commented Feb 3, 2026

Description

Issue(s)

  • Close/close/Fix/fix/Resolve/resolve: Issue Link

Checklist

Please check the items in the checklist if applicable.

  • Is the user manual updated?
  • Are the test cases passed and automated?
  • Is there no significant decrease in test coverage?

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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 05_MultiDisk unit test within tfsTest.cpp. The changes make the test more resilient to variations in disk allocation order by validating that allocated disk IDs fall within expected ranges and follow a cyclic pattern, rather than asserting against specific, fixed IDs. This ensures the test accurately reflects the intended behavior of the multi-disk allocation system, even if the exact ID assignment changes, thus preventing potential false negatives.

Highlights

  • Test Robustness: Enhanced the 05_MultiDisk unit test case in tfsTest.cpp to be more robust by validating disk ID ranges and cyclic allocation behavior instead of relying on fixed disk IDs.
  • Code Refactoring: Introduced a rootArr 2D array to store disk root paths, improving the organization and dynamic access of test paths within the 05_MultiDisk test.
  • Assertion Logic Update: Modified EXPECT_EQ assertions for did.id to check for valid ranges and cyclic patterns, and updated EXPECT_STREQ assertions to use the rootArr for dynamic path validation.

🧠 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
  • source/libs/tfs/test/tfsTest.cpp
    • Introduced a rootArr 2D array to consolidate and manage disk root paths, replacing individual rootXX variables.
    • Updated EXPECT_EQ assertions for did.id to check for valid ranges (0 <= did.id && did.id <= Y) and cyclic allocation ((lastId + 1) % Z) instead of specific values.
    • Modified EXPECT_STREQ assertions to dynamically retrieve disk paths from the rootArr using did.id and did.level.
Activity
  • The pull request introduces an enhancement to a unit test.
  • No specific review comments or progress updates are available in the provided context.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 434 to +485
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]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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]);
    }

@guanshengliang guanshengliang merged commit 3a8b5f1 into main Feb 3, 2026
13 of 14 checks passed
@guanshengliang guanshengliang deleted the fix/TD-6579338695-main branch February 3, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants