Skip to content

Commit cbc7e86

Browse files
committed
test(loadbalancer/maglev): lock Hash determinism for the same key
Regression coverage for the previous random-seed bug. Calls Hash on the same key 20 times and asserts stability.
1 parent 1646021 commit cbc7e86

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

pkg/cluster/loadbalancer/maglev/maglev_hash_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,17 @@ func TestMaglevHash(t *testing.T) {
6060
}
6161

6262
}
63+
64+
func TestLookUpTableHashIsStableForSameKey(t *testing.T) {
65+
table, err := NewLookUpTable(521, []string{"127.0.0.1:18080", "127.0.0.1:18081"})
66+
if err != nil {
67+
t.Fatalf("NewLookUpTable() error = %v", err)
68+
}
69+
70+
first := table.Hash("same-request-key")
71+
for i := 0; i < 20; i++ {
72+
if got := table.Hash("same-request-key"); got != first {
73+
t.Fatalf("Hash() = %d, want stable %d", got, first)
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)