Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reparent tests refactoring: setup/teardown for each test, reduce cut/paste, improve readability #6726

Merged
merged 5 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 0 additions & 180 deletions go/test/endtoend/reparent/main_test.go

This file was deleted.

65 changes: 11 additions & 54 deletions go/test/endtoend/reparent/reparent_range_based_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,74 +18,31 @@ package reparent

import (
"context"
"fmt"
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"vitess.io/vitess/go/test/endtoend/cluster"
)

var (
masterTablet *cluster.Vttablet
replicaTablet *cluster.Vttablet
)

func TestReparentGracefulRangeBased(t *testing.T) {
defer cluster.PanicHandler(t)
ctx := context.Background()

for _, tablet := range []cluster.Vttablet{*masterTablet, *replicaTablet} {
// create database
err := tablet.VttabletProcess.CreateDB(keyspaceName)
require.NoError(t, err)
// Start the tablet
err = tablet.VttabletProcess.Setup()
require.NoError(t, err)
}

for _, tablet := range []cluster.Vttablet{*masterTablet, *replicaTablet} {
err := tablet.VttabletProcess.WaitForTabletTypes([]string{"SERVING", "NOT_SERVING"})
require.NoError(t, err)
}

// Force the replica to reparent assuming that all the datasets are identical.
err := clusterInstance.VtctlclientProcess.ExecuteCommand("InitShardMaster",
"-force", fmt.Sprintf("%s/%s", keyspaceName, shard1Name), masterTablet.Alias)
require.NoError(t, err)

// Validate topology
validateTopology(t, true)
shardName = "0000000000000000-ffffffffffffffff"
defer func() { shardName = "0" }()

// create Tables
runSQL(ctx, t, sqlSchema, masterTablet)

checkMasterTablet(t, masterTablet)

validateTopology(t, false)

// Run this to make sure it succeeds.
output, err := clusterInstance.VtctlclientProcess.ExecuteCommandWithOutput(
"ShardReplicationPositions", fmt.Sprintf("%s/%s", keyspaceName, shard1Name))
require.NoError(t, err)
strArray := strings.Split(output, "\n")
if strArray[len(strArray)-1] == "" {
strArray = strArray[:len(strArray)-1] // Truncate slice, remove empty line
}
assert.Equal(t, 2, len(strArray)) // one master, one replica
assert.Contains(t, strArray[0], "master") // master first
setupRangeBasedCluster(ctx, t)
defer teardownCluster()

// Perform a graceful reparent operation
err = clusterInstance.VtctlclientProcess.ExecuteCommand(
"PlannedReparentShard",
"-keyspace_shard", fmt.Sprintf("%s/%s", keyspaceName, shard1Name),
"-new_master", replicaTablet.Alias)
_, err := prs(t, replicaTablet)
require.NoError(t, err)

// Validate topology
validateTopology(t, false)

checkMasterTablet(t, replicaTablet)

// insert data into the new master, check the connected replica work
insertSQL := fmt.Sprintf(insertSQL, 1, 1)
runSQL(ctx, t, insertSQL, replicaTablet)
err = checkInsertedValues(ctx, t, masterTablet, 1)
require.NoError(t, err)
confirmReplication(t, replicaTablet, []*cluster.Vttablet{masterTablet})
}
Loading