Skip to content

Improve Test Coverage to >85%#15

Open
poyrazK wants to merge 4 commits intomainfrom
feature/improve-coverage
Open

Improve Test Coverage to >85%#15
poyrazK wants to merge 4 commits intomainfrom
feature/improve-coverage

Conversation

@poyrazK
Copy link
Owner

@poyrazK poyrazK commented Mar 15, 2026

This PR implements the test coverage improvement plan by targeting the weakest modules: Catalog, Transaction, and Network/Utils. It adds 3 new test suites and integrates them into the CI pipeline.

Summary by CodeRabbit

  • Tests
    • Added comprehensive unit test coverage for transaction management system, including concurrency behavior and rollback scenarios
    • Added catalog module tests covering entity operations and edge cases
    • Added utility component tests validating error handling and boundary conditions

@coderabbitai
Copy link

coderabbitai bot commented Mar 15, 2026

📝 Walkthrough

Walkthrough

This PR adds three new test suites to increase code coverage: catalog_coverage_tests for Catalog module operations, transaction_coverage_tests for concurrent locking and rollback scenarios, and utils_coverage_tests for Value and RpcClient edge cases. Updates CMakeLists.txt to register these test targets.

Changes

Cohort / File(s) Summary
Build Configuration
CMakeLists.txt
Registers three new test targets (catalog_coverage_tests, transaction_coverage_tests, utils_coverage_tests) via the add_cloudsql_test macro under the BUILD_TESTS block.
Coverage Tests
tests/catalog_coverage_tests.cpp, tests/transaction_coverage_tests.cpp, tests/utils_coverage_tests.cpp
Adds three new test files targeting edge cases and failure scenarios: Catalog operations (missing/duplicate entities, Raft replay), concurrent transaction locking and rollback behavior, and Value/RpcClient boundary conditions and error paths.

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly Related PRs

Poem

🐰 Three test suites hopping through the code,
Catalog paths, transactions, and utils strode,
Coverage grows as assertions play,
Edge cases caught and rolled away! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Improve Test Coverage to >85%' clearly summarizes the main objective of the pull request, which is to increase test coverage above 85% by adding three new test suites for Catalog, Transaction, and Utils modules.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/improve-coverage
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
tests/utils_coverage_tests.cpp (1)

86-96: Test covers connection failure paths well, but consider potential flakiness.

The test uses port 1 which is typically privileged and closed, but network behavior can vary across environments. If CI runs in containers with different network configurations, this test might behave unexpectedly. Consider adding a comment documenting this assumption, or using a mock/stub approach for more deterministic testing.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/utils_coverage_tests.cpp` around lines 86 - 96, The test relies on
reaching an unreachable service on localhost (RpcClient constructor,
connect/is_connected/call/send_only) which can be flaky; replace the hardcoded
localhost+port assumption by using a non-routable TEST-NET address (e.g.,
192.0.2.1) or, preferably, refactor to a deterministic stub/mock of RpcClient
and call the same methods (connect, is_connected, call, send_only) to simulate
failure; also add a short comment explaining the chosen approach and why it
avoids CI network variability so the intent is clear.
tests/transaction_coverage_tests.cpp (1)

78-135: Good rollback coverage, but cleanup could be more robust.

The test correctly exercises the undo log paths for INSERT, UPDATE (with old_rid), and DELETE operations, verifying that tm.abort() properly reverses all changes.

Consider using a test fixture with SetUp/TearDown to ensure cleanup runs even if assertions fail:

♻️ Suggested improvement for robust cleanup
+class TransactionCoverageTestFixture : public ::testing::Test {
+protected:
+    void TearDown() override {
+        std::remove("./test_data/rollback_stress.heap");
+        // Consider also cleaning up the directory if needed
+    }
+};

-TEST(TransactionCoverageTests, DeepRollback) {
+TEST_F(TransactionCoverageTestFixture, DeepRollback) {
     // ... test body ...
-    static_cast<void>(std::remove("./test_data/rollback_stress.heap"));
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/transaction_coverage_tests.cpp` around lines 78 - 135, Replace the
standalone TEST( TransactionCoverageTests, DeepRollback ) with a test fixture so
cleanup always runs: create a class TransactionCoverageTests : public
::testing::Test and implement SetUp to initialize Catalog::create(),
StorageManager disk_manager, BufferPoolManager bpm, LockManager lm,
TransactionManager tm, and create the HeapTable used by the test; implement
TearDown to abort any live Transaction* txn (or call tm.abort(txn) if not
nullptr), close/remove the backing file "./test_data/rollback_stress.heap" (and
any other test_data artifacts), and release/destroy bpm and disk_manager
resources; change the test to TEST_F(TransactionCoverageTests, DeepRollback) and
remove the inline static_cast<void>(std::remove(...)) cleanup line so the
TearDown handles it. Ensure the fixture exposes the symbols used in the test
(tm, txn, table, disk_manager, bpm) so the existing test body can be reused
unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/transaction_coverage_tests.cpp`:
- Around line 78-135: Replace the standalone TEST( TransactionCoverageTests,
DeepRollback ) with a test fixture so cleanup always runs: create a class
TransactionCoverageTests : public ::testing::Test and implement SetUp to
initialize Catalog::create(), StorageManager disk_manager, BufferPoolManager
bpm, LockManager lm, TransactionManager tm, and create the HeapTable used by the
test; implement TearDown to abort any live Transaction* txn (or call
tm.abort(txn) if not nullptr), close/remove the backing file
"./test_data/rollback_stress.heap" (and any other test_data artifacts), and
release/destroy bpm and disk_manager resources; change the test to
TEST_F(TransactionCoverageTests, DeepRollback) and remove the inline
static_cast<void>(std::remove(...)) cleanup line so the TearDown handles it.
Ensure the fixture exposes the symbols used in the test (tm, txn, table,
disk_manager, bpm) so the existing test body can be reused unchanged.

In `@tests/utils_coverage_tests.cpp`:
- Around line 86-96: The test relies on reaching an unreachable service on
localhost (RpcClient constructor, connect/is_connected/call/send_only) which can
be flaky; replace the hardcoded localhost+port assumption by using a
non-routable TEST-NET address (e.g., 192.0.2.1) or, preferably, refactor to a
deterministic stub/mock of RpcClient and call the same methods (connect,
is_connected, call, send_only) to simulate failure; also add a short comment
explaining the chosen approach and why it avoids CI network variability so the
intent is clear.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cee9e2c4-18cb-4b3f-a5ee-d83382d0efe3

📥 Commits

Reviewing files that changed from the base of the PR and between 6c8ea98 and c1b467c.

📒 Files selected for processing (4)
  • CMakeLists.txt
  • tests/catalog_coverage_tests.cpp
  • tests/transaction_coverage_tests.cpp
  • tests/utils_coverage_tests.cpp

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.

1 participant