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

chore: remove useless test #612

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
72 changes: 72 additions & 0 deletions endtoend/framework/onlineddl_utils/metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package onlineddl_utils

import "time"

const (
OnlineDDLStatusRequested string = "requested"
OnlineDDLStatusCancelled string = "cancelled"
OnlineDDLStatusQueued string = "queued"
OnlineDDLStatusReady string = "ready"
OnlineDDLStatusRunning string = "running"
OnlineDDLStatusComplete string = "complete"
OnlineDDLStatusFailed string = "failed"
OnlineDDLStatusPaused string = "paused"
)

type SchemaMigrationMetadata struct {
ID int64
MigrationUUID string
Keyspace string
Shard string
MySQLSchema string `db:"mysql_schema"`
MySQLTable string `db:"mysql_table"`
MigrationStatement string
Strategy string
Options string
AddedTimestamp *time.Time
RequestedTimestamp *time.Time
ReadyTimestamp *time.Time
StartedTimestamp *time.Time
LivenessTimestamp *time.Time
CompletedTimestamp *time.Time
CleanupTimestamp *time.Time
MigrationStatus string
StatusBeforePaused *string
LogPath string
Artifacts string
Retries int
Tablet string
TabletFailure int
Progress int
MigrationContext string
DDLAction string `db:"ddl_action"`
Message string
ETASeconds int `db:"eta_seconds"`
RowsCopied int64
TableRows int64
AddedUniqueKeys int
RemovedUniqueKeys int
LogFile string
RetainArtifactsSeconds int
PostponeCompletion int
RemovedUniqueKeyNames string
DroppedNoDefaultColumnNames string
ExpandedColumnNames string
RevertibleNotes string
AllowConcurrent int
RevertedUUID string
IsView int
ReadyToComplete int
StowawayTable string
VitessLivenessIndicator int
UserThrottleRatio float64
SpecialPlan string
LastThrottledTimestamp *time.Time
ComponentThrottled string
CancelledTimestamp *time.Time
PostponeLaunch int
Stage string
CutoverAttempts int
IsImmediateOperation int
ReviewedTimestamp *time.Time
}
117 changes: 117 additions & 0 deletions endtoend/framework/onlineddl_utils/onlineddl_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package onlineddl_utils

import (
"context"
"database/sql"
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)

func VtgateExecDDL(t *testing.T, db *sql.DB, ddlStrategy string, ddl string, expectError string) string {
t.Helper()

ctx := context.Background()
conn, err := db.Conn(ctx)
assert.NoError(t, err)
defer conn.Close()

// Read original DDL strategy
var originalStrategy string
err = conn.QueryRowContext(ctx, "SELECT @@ddl_strategy").Scan(&originalStrategy)
assert.NoError(t, err)

// Set new DDL strategy
_, err = conn.ExecContext(ctx, fmt.Sprintf("SET @@ddl_strategy='%s'", ddlStrategy))
assert.NoError(t, err)

// Ensure strategy is reset after execution
defer func() {
_, err := conn.ExecContext(ctx, fmt.Sprintf("SET @@ddl_strategy='%s'", originalStrategy))
assert.NoError(t, err)
}()

// Execute DDL
var uuid string
err = conn.QueryRowContext(ctx, ddl).Scan(&uuid)

// Handle expected errors
if expectError == "" {
assert.NoError(t, err)
} else {
assert.Error(t, err)
assert.Contains(t, err.Error(), expectError)
}

return uuid
}

func GetSchemaMigrationMetadata(t *testing.T, db *sql.DB, uuid string) *SchemaMigrationMetadata {
t.Helper()

query := fmt.Sprintf("show vitess_migrations like '%s'", uuid)

row := db.QueryRow(query)
metadata := &SchemaMigrationMetadata{}

err := row.Scan(
&metadata.ID,
&metadata.MigrationUUID,
&metadata.Keyspace,
&metadata.Shard,
&metadata.MySQLSchema,
&metadata.MySQLTable,
&metadata.MigrationStatement,
&metadata.Strategy,
&metadata.Options,
&metadata.AddedTimestamp,
&metadata.RequestedTimestamp,
&metadata.ReadyTimestamp,
&metadata.StartedTimestamp,
&metadata.LivenessTimestamp,
&metadata.CompletedTimestamp,
&metadata.CleanupTimestamp,
&metadata.MigrationStatus,
&metadata.StatusBeforePaused,
&metadata.LogPath,
&metadata.Artifacts,
&metadata.Retries,
&metadata.Tablet,
&metadata.TabletFailure,
&metadata.Progress,
&metadata.MigrationContext,
&metadata.DDLAction,
&metadata.Message,
&metadata.ETASeconds,
&metadata.RowsCopied,
&metadata.TableRows,
&metadata.AddedUniqueKeys,
&metadata.RemovedUniqueKeys,
&metadata.LogFile,
&metadata.RetainArtifactsSeconds,
&metadata.PostponeCompletion,
&metadata.RemovedUniqueKeyNames,
&metadata.DroppedNoDefaultColumnNames,
&metadata.ExpandedColumnNames,
&metadata.RevertibleNotes,
&metadata.AllowConcurrent,
&metadata.RevertedUUID,
&metadata.IsView,
&metadata.ReadyToComplete,
&metadata.StowawayTable,
&metadata.VitessLivenessIndicator,
&metadata.UserThrottleRatio,
&metadata.SpecialPlan,
&metadata.LastThrottledTimestamp,
&metadata.ComponentThrottled,
&metadata.CancelledTimestamp,
&metadata.PostponeLaunch,
&metadata.Stage,
&metadata.CutoverAttempts,
&metadata.IsImmediateOperation,
&metadata.ReviewedTimestamp,
)

assert.NoError(t, err)
return metadata
}
19 changes: 13 additions & 6 deletions endtoend/framework/sql_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,26 @@ func ExecNoError(t *testing.T, db *sql.DB, sql string, args ...any) {
assert.NoError(t, err)
}

func QueryNoError(t *testing.T, db *sql.DB, sql string, args ...any) *sql.Rows {
func ExecWithErrorContains(t *testing.T, db *sql.DB, contains string, sql string, args ...any) {
t.Helper()
log.Println(sql)
_, err := db.Exec(sql, args...)
assert.ErrorContains(t, err, contains)
}

func Query(t *testing.T, db *sql.DB, sql string, args ...any) (*sql.Rows, error) {
t.Helper()
log.Println(sql)
rows, err := db.Query(sql, args...)
assert.NoError(t, err)
return rows
return rows, err
}

func ExecWithErrorContains(t *testing.T, db *sql.DB, contains string, sql string, args ...any) {
func QueryNoError(t *testing.T, db *sql.DB, sql string, args ...any) *sql.Rows {
t.Helper()
log.Println(sql)
_, err := db.Exec(sql, args...)
assert.ErrorContains(t, err, contains)
rows, err := db.Query(sql, args...)
assert.NoError(t, err)
return rows
}

func QueryWithErrorContains(t *testing.T, db *sql.DB, contains string, sql string, args ...any) {
Expand Down
Empty file.
43 changes: 43 additions & 0 deletions endtoend/onlineddl/scheduler/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package scheduler

import (
_ "embed"
"flag"
"github.com/wesql/wescale/endtoend/framework/clusters"
"log"
"os"
"testing"
)

var dbName = "onlineddl_scheduler_e2e_test"

//go:embed setup.sql
var setupSql string

//go:embed cleanup.sql
var cleanupSql string

var cluster *clusters.SingleNodeCluster

func TestMain(m *testing.M) {
cluster = clusters.NewDefaultSingleNodeCluster()
cluster.RegisterFlagsForSingleNodeCluster()
flag.Parse()

// Setup the test environment
err := cluster.SetUp(dbName, setupSql)
if err != nil {
log.Fatalf("Setup failed: %v", err)
}

// Run the tests
code := m.Run()

// Cleanup the test environment
err = cluster.CleanUp(cleanupSql)
if err != nil {
log.Fatalf("Cleanup failed: %v", err)
}

os.Exit(code)
}
1 change: 1 addition & 0 deletions endtoend/onlineddl/scheduler/onlineddl_scheduler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package scheduler
Empty file.
Loading
Loading