Skip to content

test: add distributed_executor and ShardManager unit tests#27

Open
poyrazK wants to merge 2 commits intomainfrom
test/distributed-executor-coverage
Open

test: add distributed_executor and ShardManager unit tests#27
poyrazK wants to merge 2 commits intomainfrom
test/distributed-executor-coverage

Conversation

@poyrazK
Copy link
Copy Markdown
Owner

@poyrazK poyrazK commented Apr 11, 2026

Summary

Add unit tests for distributed_executor.cpp and shard_manager.cpp:

ShardManager Tests

  • stable_hash consistency and algorithm verification
  • compute_shard determinism, zero shards edge case, modulo range
  • get_target_node found/not found scenarios

DistributedExecutor Tests

  • DDL operations (CREATE/DROP TABLE) succeed without data nodes (local catalog update)
  • DML operations (INSERT, UPDATE, DELETE) require data nodes
  • SELECT requires data nodes
  • Transaction control (BEGIN, COMMIT, ROLLBACK) requires data nodes

Parser/Expression Tests

  • WHERE clause extraction in sharded queries
  • Non-equality conditions

Test Plan

  • 26 tests pass locally
  • All 25 test suites pass via ctest
  • CI builds pass

Part of ongoing coverage improvement effort.

Summary by CodeRabbit

Tests

  • Expanded test coverage for distributed execution infrastructure.

Add unit tests covering:
- ShardManager: stable_hash, compute_shard, get_target_node
- DistributedExecutor: DDL succeeds (local catalog), DML/SELECT/transaction fails without nodes
- Sharding key extraction via parser (where clause tests)
- Null safety: verify correct success/failure per statement type

Part of ongoing coverage improvement effort.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 11, 2026

📝 Walkthrough

Walkthrough

A new test executable is registered in the CMake build system for distributed executor tests, with a comprehensive GoogleTest suite added covering ShardManager utilities (hash computation, shard assignment) and DistributedExecutor baseline behaviors under various cluster configurations.

Changes

Cohort / File(s) Summary
Build Configuration
CMakeLists.txt
Registers new test executable distributed_executor_tests linking against sqlEngineCore and Google Test libraries.
Test Suite
tests/distributed_executor_tests.cpp
Adds 341 lines of unit tests for ShardManager (hash stability, shard computation, node targeting) and DistributedExecutor (DDL/DML/transaction execution with zero active nodes, error handling, parser validation).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A test suite hops into the fold,
With ShardManager tales to be told,
Hash values steady, shards arranged just right,
DistributedExecutor tested with all its might!
Three hundred lines of coverage so true, 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 32.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately summarizes the main change: adding unit tests for distributed_executor and ShardManager components, which is clearly reflected in both the file modifications (CMakeLists.txt registration and the new test file).

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/distributed-executor-coverage

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.

Actionable comments posted: 1

🧹 Nitpick comments (3)
tests/distributed_executor_tests.cpp (3)

307-307: Remove tautological unsigned assertion.

Line 307 (EXPECT_GE(shard, 0)) is always true for uint32_t and adds no signal.

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

In `@tests/distributed_executor_tests.cpp` at line 307, The assertion
EXPECT_GE(shard, 0) is tautological because shard is an unsigned type
(uint32_t); remove this redundant check from
tests/distributed_executor_tests.cpp (the expectation referencing variable
shard) so the test only contains meaningful assertions, or replace it with a
more relevant check (e.g., bounds against a known max_shards or validate
non-empty shard set) if additional validation is required.

217-223: Rename this test to match what it actually validates.

This case validates parser rejection of an incomplete SELECT *, not an “unknown statement type.” A clearer name will reduce confusion during failures.

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

In `@tests/distributed_executor_tests.cpp` around lines 217 - 223, Rename the test
that currently uses TEST_F(DistributedExecutorTests,
ExecuteUnknownStatementType) to a name that reflects its purpose (e.g.,
ParseRejectsIncompleteSelect or RejectsSelectWithoutFrom) so it clearly
documents that it validates parser rejection of an incomplete "SELECT *"
statement; update the TEST_F identifier and any references to the test name
accordingly in this test case where Lexer("SELECT *"),
Parser::parse_statement(), and the ASSERT_EQ(stmt, nullptr) assertion are used.

233-248: These extraction tests assert structure, not extraction behavior.

The tests named for sharding-key extraction/non-equality currently only verify that a WHERE node exists. That gives weak coverage for the behavior implied by the test names and PR objective.

Also applies to: 261-270

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

In `@tests/distributed_executor_tests.cpp` around lines 233 - 248, The tests
(ShardingKeyExtractionTests::ExtractShardingKeySimpleEq and the similar
non-equality test) only assert the presence of a WHERE node instead of verifying
the actual sharding-key extraction behavior; update the tests to assert the
extracted sharding key value (e.g., that the helper in distributed_executor.cpp
yields Value 42 for "id = 42") and that the non-equality test correctly reports
"no sharding key" (or equivalent). To do this, either call the sharding-key
extraction helper via a test-only accessor or drive the public execute path that
returns the extracted key, then replace the current ASSERT/EXPECT on
select_stmt->where() with assertions comparing the returned Value or
presence/absence flag; refer to the test names (ExtractShardingKeySimpleEq, the
non-eq test) and the sharding-key extraction helper in distributed_executor.cpp
when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/distributed_executor_tests.cpp`:
- Around line 330-337: The loop currently skips assertions when parsing fails;
ensure parsing failures fail the test by asserting the parse result before using
it—after calling Parser::parse_statement() check that stmt is not null (e.g.,
use ASSERT_TRUE(stmt) or EXPECT_TRUE(stmt) with a message) so that a failed
parse for a given SQL string (reference Lexer, Parser, parse_statement, stmt)
causes the test to fail and includes the SQL in the failure message before
calling exec.execute or EXPECT_EQ on res.success().

---

Nitpick comments:
In `@tests/distributed_executor_tests.cpp`:
- Line 307: The assertion EXPECT_GE(shard, 0) is tautological because shard is
an unsigned type (uint32_t); remove this redundant check from
tests/distributed_executor_tests.cpp (the expectation referencing variable
shard) so the test only contains meaningful assertions, or replace it with a
more relevant check (e.g., bounds against a known max_shards or validate
non-empty shard set) if additional validation is required.
- Around line 217-223: Rename the test that currently uses
TEST_F(DistributedExecutorTests, ExecuteUnknownStatementType) to a name that
reflects its purpose (e.g., ParseRejectsIncompleteSelect or
RejectsSelectWithoutFrom) so it clearly documents that it validates parser
rejection of an incomplete "SELECT *" statement; update the TEST_F identifier
and any references to the test name accordingly in this test case where
Lexer("SELECT *"), Parser::parse_statement(), and the ASSERT_EQ(stmt, nullptr)
assertion are used.
- Around line 233-248: The tests
(ShardingKeyExtractionTests::ExtractShardingKeySimpleEq and the similar
non-equality test) only assert the presence of a WHERE node instead of verifying
the actual sharding-key extraction behavior; update the tests to assert the
extracted sharding key value (e.g., that the helper in distributed_executor.cpp
yields Value 42 for "id = 42") and that the non-equality test correctly reports
"no sharding key" (or equivalent). To do this, either call the sharding-key
extraction helper via a test-only accessor or drive the public execute path that
returns the extracted key, then replace the current ASSERT/EXPECT on
select_stmt->where() with assertions comparing the returned Value or
presence/absence flag; refer to the test names (ExtractShardingKeySimpleEq, the
non-eq test) and the sharding-key extraction helper in distributed_executor.cpp
when making the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9aed1e6f-aba7-4fff-95ab-059194752d96

📥 Commits

Reviewing files that changed from the base of the PR and between b7fb93d and 9aaf4cc.

📒 Files selected for processing (2)
  • CMakeLists.txt
  • tests/distributed_executor_tests.cpp

Comment on lines +330 to +337
for (const auto& [sql, expected_success] : statements) {
auto lexer = std::make_unique<Lexer>(sql);
Parser parser(std::move(lexer));
auto stmt = parser.parse_statement();
if (stmt) {
auto res = exec.execute(*stmt, sql);
EXPECT_EQ(res.success(), expected_success) << "Failed for: " << sql;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Do not silently skip failed parses in this loop.

Line 334 currently bypasses assertions when parsing fails, so this test can pass while statements are no longer parseable.

Proposed fix
 for (const auto& [sql, expected_success] : statements) {
     auto lexer = std::make_unique<Lexer>(sql);
     Parser parser(std::move(lexer));
     auto stmt = parser.parse_statement();
-    if (stmt) {
-        auto res = exec.execute(*stmt, sql);
-        EXPECT_EQ(res.success(), expected_success) << "Failed for: " << sql;
-    }
+    ASSERT_NE(stmt, nullptr) << "Parser failed for: " << sql;
+    auto res = exec.execute(*stmt, sql);
+    EXPECT_EQ(res.success(), expected_success) << "Failed for: " << sql;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/distributed_executor_tests.cpp` around lines 330 - 337, The loop
currently skips assertions when parsing fails; ensure parsing failures fail the
test by asserting the parse result before using it—after calling
Parser::parse_statement() check that stmt is not null (e.g., use
ASSERT_TRUE(stmt) or EXPECT_TRUE(stmt) with a message) so that a failed parse
for a given SQL string (reference Lexer, Parser, parse_statement, stmt) causes
the test to fail and includes the SQL in the failure message before calling
exec.execute or EXPECT_EQ on res.success().

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