From 2e88c450f87c5f65a7d9e39c2ecd24176508cfce Mon Sep 17 00:00:00 2001 From: Venkatraju V Date: Mon, 8 Jul 2024 16:48:31 -0700 Subject: [PATCH] tabletbalancer test coverage for tablet replaced Signed-off-by: Venkatraju V --- go/vt/vtgate/balancer/balancer_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/go/vt/vtgate/balancer/balancer_test.go b/go/vt/vtgate/balancer/balancer_test.go index 0318fda1391..e110f3fc5c0 100644 --- a/go/vt/vtgate/balancer/balancer_test.go +++ b/go/vt/vtgate/balancer/balancer_test.go @@ -384,4 +384,26 @@ func TestTopologyChanged(t *testing.T) { t.Errorf("shuffle promoted wrong tablet from cell %s", allTablets[0].Tablet.Alias.Cell) } } + + // Run again with a node in the topology replaced. + newTablet := createTestTablet("b") + allTablets[2] = newTablet + for i := 0; i < N; i++ { + th := b.Pick(target, allTablets) + + allocation, totalAllocation := b.getAllocation(target, allTablets) + + if totalAllocation != ALLOCATION/2 { + t.Errorf("totalAllocation mismatch %s", b.print()) + } + + if allocation[th.Tablet.Alias.Uid] != ALLOCATION/4 { + t.Errorf("allocation mismatch %s, cell %s", b.print(), allTablets[0].Tablet.Alias.Cell) + } + + if th.Tablet.Alias.Cell != "b" { + t.Errorf("shuffle promoted wrong tablet from cell %s", allTablets[0].Tablet.Alias.Cell) + } + } + }