Skip to content

Commit

Permalink
endtoend tests for --retain-artifacts flag
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach committed Sep 19, 2023
1 parent 507990b commit 92b9cab
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions go/test/endtoend/onlineddl/scheduler/onlineddl_scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,60 @@ func testScheduler(t *testing.T) {
})
})

t.Run("Cleanup artifacts", func(t *testing.T) {
// Create a migration with a low --retain-artifacts value.
// We will cancel the migration and expect the artifact to be cleaned.
t.Run("start migration", func(t *testing.T) {
t1uuid = testOnlineDDLStatement(t, createParams(trivialAlterT1Statement, ddlStrategy+" --postpone-completion --retain-artifacts=1s", "vtctl", "", "", true)) // skip wait
onlineddl.WaitForMigrationStatus(t, &vtParams, shards, t1uuid, normalWaitTime, schema.OnlineDDLStatusRunning)
})
var artifacts []string
t.Run("validate artifact exists", func(t *testing.T) {
rs := onlineddl.ReadMigrations(t, &vtParams, t1uuid)
require.NotNil(t, rs)
row := rs.Named().Row()
require.NotNil(t, row)

artifacts = textutil.SplitDelimitedList(row.AsString("artifacts", ""))
assert.NotEmpty(t, artifacts)
assert.Equal(t, 1, len(artifacts))
checkTable(t, artifacts[0], true)

retainArtifactsSeconds := row.AsInt64("retain_artifacts_seconds", 0)
assert.Equal(t, int64(1), retainArtifactsSeconds) // due to --retain-artifacts=1s
})
t.Run("cancel migration", func(t *testing.T) {
onlineddl.CheckCancelMigration(t, &vtParams, shards, t1uuid, true)
status := onlineddl.WaitForMigrationStatus(t, &vtParams, shards, t1uuid, normalWaitTime, schema.OnlineDDLStatusFailed, schema.OnlineDDLStatusCancelled)
fmt.Printf("# Migration status (for debug purposes): <%s>\n", status)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, t1uuid, schema.OnlineDDLStatusCancelled)
})
t.Run("wait for cleanup", func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), normalWaitTime)
defer cancel()

for {
rs := onlineddl.ReadMigrations(t, &vtParams, t1uuid)
require.NotNil(t, rs)
row := rs.Named().Row()
require.NotNil(t, row)
if !row["cleanup_timestamp"].IsNull() {
// This is what we've been waiting for
break
}
select {
case <-ctx.Done():
assert.Fail(t, "timeout waiting for cleanup")
return
case <-time.After(time.Second):
}
}
})
t.Run("validate artifact does not exist", func(t *testing.T) {
checkTable(t, artifacts[0], false)
})
})

// INSTANT DDL
instantDDLCapable, err := capableOf(mysql.InstantAddLastColumnFlavorCapability)
require.NoError(t, err)
Expand Down

0 comments on commit 92b9cab

Please sign in to comment.