Skip to content

Commit

Permalink
Cherry-pick bad431d with conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
vitess-bot[bot] authored and vitess-bot committed Dec 10, 2024
1 parent f0d9386 commit 337a2d8
Show file tree
Hide file tree
Showing 160 changed files with 2,632 additions and 378 deletions.
2 changes: 0 additions & 2 deletions go/test/endtoend/backup/vtbackup/backup_only_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func TestTabletInitialBackup(t *testing.T) {
// - Take a Second Backup
// - Bring up a second replica, and restore from the second backup
// - list the backups, remove them
defer cluster.PanicHandler(t)

waitForReplicationToCatchup([]cluster.Vttablet{*replica1, *replica2})

Expand Down Expand Up @@ -102,7 +101,6 @@ func TestTabletBackupOnly(t *testing.T) {
// - Take a Second Backup
// - Bring up a second replica, and restore from the second backup
// - list the backups, remove them
defer cluster.PanicHandler(t)

// Reset the tablet object values in order on init tablet in the next step.
primary.VttabletProcess.ServingStatus = "NOT_SERVING"
Expand Down
1 change: 0 additions & 1 deletion go/test/endtoend/backup/vtbackup/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ var (
)

func TestMain(m *testing.M) {
defer cluster.PanicHandler(nil)
flag.Parse()

exitCode, err := func() (int, error) {
Expand Down
148 changes: 147 additions & 1 deletion go/test/endtoend/backup/vtctlbackup/backup_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ func TestBackup(t *testing.T, setupType int, streamMode string, stripes int, cDe
}, //
}

defer cluster.PanicHandler(t)
// setup cluster for the testing
code, err := LaunchCluster(setupType, streamMode, stripes, cDetails)
require.Nilf(t, err, "setup failed with status code %d", code)
Expand Down Expand Up @@ -1430,3 +1429,150 @@ func verifyTabletRestoreStats(t *testing.T, vars map[string]any) {
}
require.Contains(t, bd, "BackupStorage.File.File:Read")
}
<<<<<<< HEAD
=======

func getDefaultCommonArgs() []string {
return []string{
"--vreplication_retry_delay", "1s",
"--degraded_threshold", "5s",
"--lock_tables_timeout", "5s",
"--watch_replication_stream",
"--enable_replication_reporter",
"--serving_state_grace_period", "1s",
}
}

func setDefaultCommonArgs() { commonTabletArg = getDefaultCommonArgs() }

// fetch the backup engine used on the last backup triggered by the end-to-end tests.
func getBackupEngineOfLastBackup(t *testing.T) string {
lastBackup := getLastBackup(t)

manifest := readManifestFile(t, path.Join(localCluster.CurrentVTDATAROOT, "backups", keyspaceName, shardName, lastBackup))

return manifest.BackupMethod
}

func getLastBackup(t *testing.T) string {
backups, err := localCluster.ListBackups(shardKsName)
require.NoError(t, err)

return backups[len(backups)-1]
}

func TestBackupEngineSelector(t *testing.T) {
defer setDefaultCommonArgs()

// launch the custer with xtrabackup as the default engine
code, err := LaunchCluster(XtraBackup, "xbstream", 0, &CompressionDetails{CompressorEngineName: "pgzip"})
require.Nilf(t, err, "setup failed with status code %d", code)

defer TearDownCluster()

localCluster.DisableVTOrcRecoveries(t)
defer func() {
localCluster.EnableVTOrcRecoveries(t)
}()
verifyInitialReplication(t)

t.Run("backup with backup-engine=builtin", func(t *testing.T) {
// first try to backup with an alternative engine (builtin)
err = localCluster.VtctldClientProcess.ExecuteCommand("Backup", "--allow-primary", "--backup-engine=builtin", primary.Alias)
require.NoError(t, err)
engineUsed := getBackupEngineOfLastBackup(t)
require.Equal(t, "builtin", engineUsed)
})

t.Run("backup with backup-engine=xtrabackup", func(t *testing.T) {
// then try to backup specifying the xtrabackup engine
err = localCluster.VtctldClientProcess.ExecuteCommand("Backup", "--allow-primary", "--backup-engine=xtrabackup", primary.Alias)
require.NoError(t, err)
engineUsed := getBackupEngineOfLastBackup(t)
require.Equal(t, "xtrabackup", engineUsed)
})

t.Run("backup without specifying backup-engine", func(t *testing.T) {
// check that by default we still use the xtrabackup engine if not specified
err = localCluster.VtctldClientProcess.ExecuteCommand("Backup", "--allow-primary", primary.Alias)
require.NoError(t, err)
engineUsed := getBackupEngineOfLastBackup(t)
require.Equal(t, "xtrabackup", engineUsed)
})
}

func TestRestoreAllowedBackupEngines(t *testing.T) {
defer setDefaultCommonArgs()

backupMsg := "right after xtrabackup backup"

cDetails := &CompressionDetails{CompressorEngineName: "pgzip"}

// launch the custer with xtrabackup as the default engine
code, err := LaunchCluster(XtraBackup, "xbstream", 0, cDetails)
require.Nilf(t, err, "setup failed with status code %d", code)

defer TearDownCluster()

localCluster.DisableVTOrcRecoveries(t)
defer func() {
localCluster.EnableVTOrcRecoveries(t)
}()
verifyInitialReplication(t)

t.Run("generate backups", func(t *testing.T) {
// lets take two backups, each using a different backup engine
err = localCluster.VtctldClientProcess.ExecuteCommand("Backup", "--allow-primary", "--backup-engine=builtin", primary.Alias)
require.NoError(t, err)

err = localCluster.VtctldClientProcess.ExecuteCommand("Backup", "--allow-primary", "--backup-engine=xtrabackup", primary.Alias)
require.NoError(t, err)
})

// insert more data on the primary
_, err = primary.VttabletProcess.QueryTablet(fmt.Sprintf("insert into vt_insert_test (msg) values ('%s')", backupMsg), keyspaceName, true)
require.NoError(t, err)

t.Run("restore replica and verify data", func(t *testing.T) {
// now bring up another replica, letting it restore from backup.
restoreWaitForBackup(t, "replica", cDetails, true)
err = replica2.VttabletProcess.WaitForTabletStatusesForTimeout([]string{"SERVING"}, timeout)
require.NoError(t, err)

// check the new replica has the data
cluster.VerifyRowsInTablet(t, replica2, keyspaceName, 2)
result, err := replica2.VttabletProcess.QueryTablet(
fmt.Sprintf("select msg from vt_insert_test where msg='%s'", backupMsg), replica2.VttabletProcess.Keyspace, true)
require.NoError(t, err)
require.Equal(t, backupMsg, result.Named().Row().AsString("msg", ""))
})

t.Run("test broken restore", func(t *testing.T) {
// now lets break the last backup in the shard
err = os.Remove(path.Join(localCluster.CurrentVTDATAROOT,
"backups", keyspaceName, shardName,
getLastBackup(t), "backup.xbstream.gz"))
require.NoError(t, err)

// and try to restore from it
err = localCluster.VtctldClientProcess.ExecuteCommand("RestoreFromBackup", replica2.Alias)
require.Error(t, err) // this should fail
})

t.Run("test older working backup", func(t *testing.T) {
// now we retry but with the first backup
err = localCluster.VtctldClientProcess.ExecuteCommand("RestoreFromBackup", "--allowed-backup-engines=builtin", replica2.Alias)
require.NoError(t, err) // this should succeed

// make sure we are replicating after the restore is done
err = replica2.VttabletProcess.WaitForTabletStatusesForTimeout([]string{"SERVING"}, timeout)
require.NoError(t, err)
cluster.VerifyRowsInTablet(t, replica2, keyspaceName, 2)

result, err := replica2.VttabletProcess.QueryTablet(
fmt.Sprintf("select msg from vt_insert_test where msg='%s'", backupMsg), replica2.VttabletProcess.Keyspace, true)
require.NoError(t, err)
require.Equal(t, backupMsg, result.Named().Row().AsString("msg", ""))
})
}
>>>>>>> bad431deed (Remove broken panic handler (#17354))
3 changes: 0 additions & 3 deletions go/test/endtoend/backup/vtctlbackup/pitr_test_framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func waitForReplica(t *testing.T, replicaIndex int) {
// in between, it makes writes to the database, and takes notes: what data was available in what backup.
// It then restores each and every one of those backups, in random order, and expects to find the specific data associated with the backup.
func ExecTestIncrementalBackupAndRestoreToPos(t *testing.T, tcase *PITRTestCase) {
defer cluster.PanicHandler(t)

t.Run(tcase.Name, func(t *testing.T) {
// setup cluster for the testing
Expand Down Expand Up @@ -320,7 +319,6 @@ func ExecTestIncrementalBackupAndRestoreToPos(t *testing.T, tcase *PITRTestCase)

// ExecTestIncrementalBackupAndRestoreToPos
func ExecTestIncrementalBackupAndRestoreToTimestamp(t *testing.T, tcase *PITRTestCase) {
defer cluster.PanicHandler(t)

var lastInsertedRowTimestamp time.Time
insertRowOnPrimary := func(t *testing.T, hint string) {
Expand Down Expand Up @@ -580,7 +578,6 @@ func ExecTestIncrementalBackupAndRestoreToTimestamp(t *testing.T, tcase *PITRTes
// Specifically, it's designed to test how incremental backups are taken by interleaved replicas, so that they successfully build on
// one another.
func ExecTestIncrementalBackupOnTwoTablets(t *testing.T, tcase *PITRTestCase) {
defer cluster.PanicHandler(t)

t.Run(tcase.Name, func(t *testing.T) {
// setup cluster for the testing
Expand Down
3 changes: 0 additions & 3 deletions go/test/endtoend/cellalias/cell_alias_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ var (
)

func TestMain(m *testing.M) {
defer cluster.PanicHandler(nil)
flag.Parse()

exitcode, err := func() (int, error) {
Expand Down Expand Up @@ -232,7 +231,6 @@ func TestMain(m *testing.M) {
}

func TestAlias(t *testing.T) {
defer cluster.PanicHandler(t)

insertInitialValues(t)
defer deleteInitialValues(t)
Expand Down Expand Up @@ -296,7 +294,6 @@ func TestAlias(t *testing.T) {
}

func TestAddAliasWhileVtgateUp(t *testing.T) {
defer cluster.PanicHandler(t)

insertInitialValues(t)
defer deleteInitialValues(t)
Expand Down
1 change: 0 additions & 1 deletion go/test/endtoend/cluster/cluster_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,6 @@ func (cluster *LocalProcessCluster) VtctlclientChangeTabletType(tablet *Vttablet

// Teardown brings down the cluster by invoking teardown for individual processes
func (cluster *LocalProcessCluster) Teardown() {
PanicHandler(nil)
cluster.mx.Lock()
defer cluster.mx.Unlock()
if cluster.teardownCompleted {
Expand Down
9 changes: 0 additions & 9 deletions go/test/endtoend/cluster/cluster_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,6 @@ func VerifyRowsInTablet(t *testing.T, vttablet *Vttablet, ksName string, expecte
VerifyRowsInTabletForTable(t, vttablet, ksName, expectedRows, "vt_insert_test")
}

// PanicHandler handles the panic in the testcase.
func PanicHandler(t testing.TB) {
err := recover()
if t == nil {
return
}
require.Nilf(t, err, "panic occured in testcase %v", t.Name())
}

// ListBackups Lists back preset in shard
func (cluster LocalProcessCluster) ListBackups(shardKsName string) ([]string, error) {
output, err := cluster.VtctlclientProcess.ExecuteCommandWithOutput("ListBackups", shardKsName)
Expand Down
1 change: 0 additions & 1 deletion go/test/endtoend/clustertest/add_keyspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ primary key (id)
)

func TestAddKeyspace(t *testing.T) {
defer cluster.PanicHandler(t)
if err := clusterInstance.StartKeyspace(*testKeyspace, []string{"-80", "80-"}, 0, false); err != nil {
log.Errorf("failed to AddKeyspace %v: %v", *testKeyspace, err)
t.Fatal(err)
Expand Down
3 changes: 0 additions & 3 deletions go/test/endtoend/clustertest/etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ import (

"github.com/stretchr/testify/require"
clientv3 "go.etcd.io/etcd/client/v3"

"vitess.io/vitess/go/test/endtoend/cluster"
)

func TestEtcdServer(t *testing.T) {
defer cluster.PanicHandler(t)

// Confirm the basic etcd cluster health.
etcdHealthURL := fmt.Sprintf("http://%s:%d/health", clusterInstance.Hostname, clusterInstance.TopoPort)
Expand Down
1 change: 0 additions & 1 deletion go/test/endtoend/clustertest/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ var (
)

func TestMain(m *testing.M) {
defer cluster.PanicHandler(nil)
flag.Parse()

exitCode := func() int {
Expand Down
3 changes: 0 additions & 3 deletions go/test/endtoend/clustertest/vtctld_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"vitess.io/vitess/go/test/endtoend/cluster"
)

var (
Expand All @@ -44,7 +42,6 @@ var (
)

func TestVtctldProcess(t *testing.T) {
defer cluster.PanicHandler(t)
url := fmt.Sprintf("http://%s:%d/api/keyspaces/", clusterInstance.Hostname, clusterInstance.VtctldHTTPPort)
testURL(t, url, "keyspace url")

Expand Down
2 changes: 0 additions & 2 deletions go/test/endtoend/clustertest/vtgate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ import (
"github.com/stretchr/testify/require"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/test/endtoend/cluster"
)

func TestVtgateProcess(t *testing.T) {
defer cluster.PanicHandler(t)
verifyVtgateVariables(t, clusterInstance.VtgateProcess.VerifyURL)
ctx := context.Background()
conn, err := mysql.Connect(ctx, &vtParams)
Expand Down
4 changes: 0 additions & 4 deletions go/test/endtoend/clustertest/vttablet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ import (
"testing"

"github.com/stretchr/testify/require"

"vitess.io/vitess/go/test/endtoend/cluster"
)

func TestVttabletProcess(t *testing.T) {
defer cluster.PanicHandler(t)
firstTabletPort := clusterInstance.Keyspaces[0].Shards[0].Vttablets[0].HTTPPort
testURL(t, fmt.Sprintf("http://localhost:%d/debug/vars/", firstTabletPort), "tablet debug var url")
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/debug/vars", firstTabletPort))
Expand All @@ -48,7 +45,6 @@ func TestVttabletProcess(t *testing.T) {
}

func TestDeleteTablet(t *testing.T) {
defer cluster.PanicHandler(t)
primary := clusterInstance.Keyspaces[0].Shards[0].PrimaryTablet()
require.NotNil(t, primary)
_, err := clusterInstance.VtctlclientProcess.ExecuteCommandWithOutput("DeleteTablet", "--", "--allow_primary", primary.Alias)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ var (

// This test makes sure that we can use SSL replication with Vitess
func TestSecure(t *testing.T) {
defer cluster.PanicHandler(t)
testReplicationBase(t, true)
testReplicationBase(t, false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ var (
)

func TestSecureTransport(t *testing.T) {
defer cluster.PanicHandler(t)
flag.Parse()

// initialize cluster
Expand Down
Loading

0 comments on commit 337a2d8

Please sign in to comment.