Skip to content

Commit 31eb6ef

Browse files
committed
test: adapt ShardRouting_Correctness for FNV-1a routing
The test relied on std::hash<int64_t> being identity (libstdc++) so that hash(3) % 3 == 0 routes id=3 to shard_1. Issue 09 replaced std::hash with FNV-1a 64-bit, which produces a different distribution. Pre-computed: FNV-1a(4) % 3 == 0, and id=4 lives on shard_1, so the test still verifies the route-to-correct-shard property without restructuring the fixture. This was missed when issue 09 landed (f0f2915) because verification focused on scripts/test_sqlengine.sh and the new tests/test_shard_map.cpp suite; the existing distributed-planner test wasn't re-run.
1 parent a90d147 commit 31eb6ef

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

tests/test_distributed_planner.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -805,15 +805,18 @@ TEST_F(DistributedPlannerTest, ShardRouting_NoShardKey_AllShards) {
805805
}
806806

807807
TEST_F(DistributedPlannerTest, ShardRouting_Correctness) {
808-
// The shard routing uses hash(id) % num_shards to pick a shard,
809-
// but the test fixture uses sequential partitioning (ids 1-5 on shard_1,
810-
// 6-10 on shard_2, 11-15 on shard_3). To verify correctness, find a
811-
// value whose hash maps to the shard that actually holds it.
808+
// The shard routing uses FNV-1a 64-bit hash of the key % num_shards
809+
// to pick a shard, but the test fixture uses sequential partitioning
810+
// (ids 1-5 on shard_1, 6-10 on shard_2, 11-15 on shard_3). To verify
811+
// correctness we need a key whose hash routes to the shard that
812+
// actually holds it.
812813
//
813-
// hash(3) % 3 == 0 => routes to shard_1 (index 0), which holds ids 1-5.
814-
// So "WHERE id = 3" should route to shard_1 and find the row.
815-
auto dist_rs = execute_distributed("SELECT * FROM users WHERE id = 3");
816-
auto local_rs = execute_local("SELECT * FROM users WHERE id = 3");
814+
// FNV-1a(4) % 3 == 0 => routes to shard_1 (index 0), which holds
815+
// ids 1-5. So "WHERE id = 4" routes to shard_1 and finds Diana.
816+
// (Until issue 09 landed this test used id=3, which worked with the
817+
// old std::hash<int64_t>=identity but not with FNV-1a.)
818+
auto dist_rs = execute_distributed("SELECT * FROM users WHERE id = 4");
819+
auto local_rs = execute_local("SELECT * FROM users WHERE id = 4");
817820

818821
EXPECT_EQ(local_rs.row_count(), 1u);
819822
EXPECT_EQ(dist_rs.row_count(), 1u);

0 commit comments

Comments
 (0)