Skip to content

test(storage_manager): add 9 new unit tests#36

Merged
poyrazK merged 2 commits intomainfrom
feat/storage-manager-tests
Apr 15, 2026
Merged

test(storage_manager): add 9 new unit tests#36
poyrazK merged 2 commits intomainfrom
feat/storage-manager-tests

Conversation

@poyrazK
Copy link
Copy Markdown
Owner

@poyrazK poyrazK commented Apr 15, 2026

Summary

Add 9 new unit tests for StorageManager to tests/storage_manager_tests.cpp.

New Tests

  1. PageSizeConstant - verify PAGE_SIZE == 4096
  2. ReadNonOpenedFileAutoOpens - verify read_page auto-opens files
  3. WriteNonOpenedFileAutoOpens - verify write_page auto-opens files
  4. DataPersistenceAcrossOpenClose - verify data persists across open/close
  5. StatsBytesAccurate - verify bytes_read and bytes_written stats
  6. MultipleFilesDataIsolation - verify data isolation between files
  7. DeallocatePageStub - verify deallocate_page doesn't crash
  8. ReadAfterWriteDifferentPatterns - verify complex patterns persist
  9. FilesOpenedStatAccurate - verify files_opened stat increments

Test plan

  • Build passes
  • All 25 tests pass (16 existing + 9 new)

Summary by CodeRabbit

  • Tests
    • Expanded test coverage for storage operations, including validation of page management, file I/O reliability, data persistence across sessions, and operational metrics tracking to enhance system stability and correctness.

- PageSizeConstant: verify PAGE_SIZE == 4096
- ReadNonOpenedFileAutoOpens: verify read_page auto-opens files
- WriteNonOpenedFileAutoOpens: verify write_page auto-opens files
- DataPersistenceAcrossOpenClose: verify data persists across open/close
- StatsBytesAccurate: verify bytes_read and bytes_written stats
- MultipleFilesDataIsolation: verify data isolation between files
- DeallocatePageStub: verify deallocate_page doesn't crash
- ReadAfterWriteDifferentPatterns: verify complex patterns persist
- FilesOpenedStatAccurate: verify files_opened stat increments
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 15, 2026

Warning

Rate limit exceeded

@poyrazK has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 42 minutes and 11 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 42 minutes and 11 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c0f96bc1-234c-44e7-913d-7459e385227c

📥 Commits

Reviewing files that changed from the base of the PR and between ef33432 and 4aa7920.

📒 Files selected for processing (1)
  • tests/storage_manager_tests.cpp
📝 Walkthrough

Walkthrough

A comprehensive test suite was added to tests/storage_manager_tests.cpp with 161 lines of new unit tests covering StorageManager functionality, including page size validation, read/write operations, file persistence, statistics tracking, data isolation, and buffer integrity. No existing tests were modified.

Changes

Cohort / File(s) Summary
StorageManager Test Suite
tests/storage_manager_tests.cpp
Added 8 test cases validating PAGE_SIZE constant (4096U), auto-open behavior during read/write operations, data persistence across file cycles, statistics counters (bytes_read, bytes_written, files_opened), data isolation between files, deallocation stub behavior, and read-after-write integrity with non-uniform byte patterns.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Hopping through the storage layers clear,
Tests now verify what we hold dear,
Pages persist, statistics gleam,
A rabbit's validation dream! 📦✨

🚥 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 'test(storage_manager): add 9 new unit tests' clearly and specifically describes the main change: addition of 9 new unit tests for StorageManager, which aligns perfectly with the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 90.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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/storage-manager-tests

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
Copy Markdown

@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 (1)
tests/storage_manager_tests.cpp (1)

248-268: Strengthen auto-open tests with side-effect checks

These two tests only verify a true return value. Add postconditions (file_exists and files_opened delta) so they prove auto-open behavior, not just success.

Suggested test hardening
 TEST_F(StorageManagerTests, ReadNonOpenedFileAutoOpens) {
     const std::string filename = "non_opened_read.db";
     cleanup_file("./test_data", filename);

+    const auto& stats = sm_->get_stats();
+    const auto initial_files_opened = stats.files_opened.load();
+
     // StorageManager auto-opens files, so read should succeed
     char buf[StorageManager::PAGE_SIZE];
-    EXPECT_TRUE(sm_->read_page(filename, 0, buf));
+    ASSERT_TRUE(sm_->read_page(filename, 0, buf));
+    EXPECT_TRUE(sm_->file_exists(filename));
+    EXPECT_EQ(stats.files_opened.load(), initial_files_opened + 1);
 }

 TEST_F(StorageManagerTests, WriteNonOpenedFileAutoOpens) {
     const std::string filename = "non_opened_write.db";
     cleanup_file("./test_data", filename);

+    const auto& stats = sm_->get_stats();
+    const auto initial_files_opened = stats.files_opened.load();
+
     char buf[StorageManager::PAGE_SIZE];
     std::memset(buf, 0xAB, StorageManager::PAGE_SIZE);
     // StorageManager auto-opens files, so write should succeed
-    EXPECT_TRUE(sm_->write_page(filename, 0, buf));
+    ASSERT_TRUE(sm_->write_page(filename, 0, buf));
+    EXPECT_TRUE(sm_->file_exists(filename));
+    EXPECT_EQ(stats.files_opened.load(), initial_files_opened + 1);
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/storage_manager_tests.cpp` around lines 248 - 268, Update the two tests
ReadNonOpenedFileAutoOpens and WriteNonOpenedFileAutoOpens to assert the
side-effects of auto-opening: before calling sm_->read_page / sm_->write_page
capture the current open-file count (e.g., auto before = sm_->files_opened();)
then after the operation assert the file was created on disk (use
file_exists("./test_data", filename)) and that the open-file count increased by
1 (EXPECT_EQ(sm_->files_opened(), before + 1)); keep existing buffer checks and
cleanup_file calls intact and use StorageManager::PAGE_SIZE for buffer sizing.
🤖 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/storage_manager_tests.cpp`:
- Around line 248-268: Update the two tests ReadNonOpenedFileAutoOpens and
WriteNonOpenedFileAutoOpens to assert the side-effects of auto-opening: before
calling sm_->read_page / sm_->write_page capture the current open-file count
(e.g., auto before = sm_->files_opened();) then after the operation assert the
file was created on disk (use file_exists("./test_data", filename)) and that the
open-file count increased by 1 (EXPECT_EQ(sm_->files_opened(), before + 1));
keep existing buffer checks and cleanup_file calls intact and use
StorageManager::PAGE_SIZE for buffer sizing.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 48ed6046-2446-44b4-96af-8ec568fe866c

📥 Commits

Reviewing files that changed from the base of the PR and between c72a39e and ef33432.

📒 Files selected for processing (1)
  • tests/storage_manager_tests.cpp

Update ReadNonOpenedFileAutoOpens and WriteNonOpenedFileAutoOpens to:
- Capture open-file count before operation
- Assert file was created on disk
- Assert open-file count increased by 1
@poyrazK poyrazK merged commit ff56ae6 into main Apr 15, 2026
9 checks passed
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