Skip to content

Commit

Permalink
test: add e2e test for allowing cross cell promotion
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <manan@planetscale.com>
  • Loading branch information
GuptaManan100 committed Jul 23, 2024
1 parent 7e9f8e6 commit c0b2a06
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
34 changes: 20 additions & 14 deletions go/test/endtoend/reparent/plannedreparent/reparent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,8 @@ func TestReparentReplicaOffline(t *testing.T) {
require.Error(t, err)

// Assert that PRS failed
if clusterInstance.VtctlMajorVersion <= 17 {
assert.True(t, utils.SetReplicationSourceFailed(tablets[3], out))
utils.CheckPrimaryTablet(t, clusterInstance, tablets[1])
} else {
assert.Contains(t, out, "rpc error: code = DeadlineExceeded desc")
utils.CheckPrimaryTablet(t, clusterInstance, tablets[0])
}

assert.Contains(t, out, "rpc error: code = DeadlineExceeded desc")
utils.CheckPrimaryTablet(t, clusterInstance, tablets[0])
}

func TestReparentAvoid(t *testing.T) {
Expand All @@ -155,20 +149,32 @@ func TestReparentAvoid(t *testing.T) {
require.NoError(t, err)
utils.ValidateTopology(t, clusterInstance, false)

// tablets[1 is in the same cell and tablets[3] is in a different cell, so we must land on tablets[1
// tablets[1] is in the same cell and tablets[3] is in a different cell, so we must land on tablets[1]
utils.CheckPrimaryTablet(t, clusterInstance, tablets[1])

// If we kill the tablet in the same cell as primary then reparent --avoid_tablet will fail.
utils.StopTablet(t, tablets[0], true)
out, err := utils.PrsAvoid(t, clusterInstance, tablets[1])
require.Error(t, err)
if clusterInstance.VtctlMajorVersion <= 17 {
assert.Contains(t, out, "cannot find a tablet to reparent to in the same cell as the current primary")
} else {
assert.Contains(t, out, "rpc error: code = DeadlineExceeded desc = latest balancer error")
}
assert.Contains(t, out, "rpc error: code = DeadlineExceeded desc = latest balancer error")
utils.ValidateTopology(t, clusterInstance, false)
utils.CheckPrimaryTablet(t, clusterInstance, tablets[1])

t.Run("Allow cross cell promotion", func(t *testing.T) {
if clusterInstance.VtctlMajorVersion <= 20 {
t.Skip("Allow Cross Cell Promotion was added in v21")
}
utils.DeleteTablet(t, clusterInstance, tablets[0])
// Perform a graceful reparent operation and verify it fails because we have no replicas in the same cell as the primary.
out, err = utils.PrsAvoid(t, clusterInstance, tablets[1])
require.Error(t, err)
assert.Contains(t, out, "is not in the same cell as the previous primary")

// If we run PRS with allow cross cell promotion then it should succeed and should promote the replica in another cell.
_, err = utils.PrsAvoid(t, clusterInstance, tablets[1], "--allow-cross-cell-promotion")
require.NoError(t, err)
utils.CheckPrimaryTablet(t, clusterInstance, tablets[3])
})
}

func TestReparentFromOutside(t *testing.T) {
Expand Down
11 changes: 6 additions & 5 deletions go/test/endtoend/reparent/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,17 @@ func execute(t *testing.T, conn *mysql.Conn, query string) *sqltypes.Result {
// region ers, prs

// Prs runs PRS
func Prs(t *testing.T, clusterInstance *cluster.LocalProcessCluster, tab *cluster.Vttablet) (string, error) {
return PrsWithTimeout(t, clusterInstance, tab, false, "", "")
func Prs(t *testing.T, clusterInstance *cluster.LocalProcessCluster, tab *cluster.Vttablet, extraArgs ...string) (string, error) {
return PrsWithTimeout(t, clusterInstance, tab, false, "", "", extraArgs...)
}

// PrsAvoid runs PRS
func PrsAvoid(t *testing.T, clusterInstance *cluster.LocalProcessCluster, tab *cluster.Vttablet) (string, error) {
return PrsWithTimeout(t, clusterInstance, tab, true, "", "")
func PrsAvoid(t *testing.T, clusterInstance *cluster.LocalProcessCluster, tab *cluster.Vttablet, extraArgs ...string) (string, error) {
return PrsWithTimeout(t, clusterInstance, tab, true, "", "", extraArgs...)
}

// PrsWithTimeout runs PRS
func PrsWithTimeout(t *testing.T, clusterInstance *cluster.LocalProcessCluster, tab *cluster.Vttablet, avoid bool, actionTimeout, waitTimeout string) (string, error) {
func PrsWithTimeout(t *testing.T, clusterInstance *cluster.LocalProcessCluster, tab *cluster.Vttablet, avoid bool, actionTimeout, waitTimeout string, extraArgs ...string) (string, error) {
args := []string{
"PlannedReparentShard",
fmt.Sprintf("%s/%s", KeyspaceName, ShardName)}
Expand All @@ -319,6 +319,7 @@ func PrsWithTimeout(t *testing.T, clusterInstance *cluster.LocalProcessCluster,
args = append(args, "--new-primary")
}
args = append(args, tab.Alias)
args = append(args, extraArgs...)
out, err := clusterInstance.VtctldClientProcess.ExecuteCommandWithOutput(args...)
return out, err
}
Expand Down

0 comments on commit c0b2a06

Please sign in to comment.