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

Fix potential panics due to "Fail in goroutine after test completed" #13596

Merged
Merged
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
88 changes: 66 additions & 22 deletions go/test/endtoend/onlineddl/revert/onlineddl_revert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,11 +764,21 @@ func testRevert(t *testing.T) {
defer wg.Done()
runMultipleConnections(ctx, t)
}()
uuid := testOnlineDDLStatementForTable(t, fmt.Sprintf(alterHintStatement, hint), "online", "vtgate", hint)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
cancel() // will cause runMultipleConnections() to terminate
wg.Wait()

func() {
// Ensures runMultipleConnections completes before the overall
// test does, even in the face of calls to t.FailNow() in the
// main goroutine, which still executes deferred functions
defer func() {
cancel() // will cause runMultipleConnections() to terminate
wg.Wait()
}()

uuid := testOnlineDDLStatementForTable(t, fmt.Sprintf(alterHintStatement, hint), "online", "vtgate", hint)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
}()

testSelectTableMetrics(t)
})
}
Expand All @@ -783,11 +793,20 @@ func testRevert(t *testing.T) {
defer wg.Done()
runMultipleConnections(ctx, t)
}()
uuid := testRevertMigration(t, uuids[len(uuids)-1], ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
cancel() // will cause runMultipleConnections() to terminate
wg.Wait()

func() {
// Ensures runMultipleConnections completes before the overall
// test does, even in the face of calls to t.FailNow() in the
// main goroutine, which still executes deferred functions
defer func() {
cancel() // will cause runMultipleConnections() to terminate
wg.Wait()
}()

uuid := testRevertMigration(t, uuids[len(uuids)-1], ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
}()
checkMigratedTable(t, tableName, alterHints[0])
testSelectTableMetrics(t)
})
Expand All @@ -802,11 +821,20 @@ func testRevert(t *testing.T) {
defer wg.Done()
runMultipleConnections(ctx, t)
}()
uuid := testRevertMigration(t, uuids[len(uuids)-1], ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
cancel() // will cause runMultipleConnections() to terminate
wg.Wait()

func() {
// Ensures runMultipleConnections completes before the overall
// test does, even in the face of calls to t.FailNow() in the
// main goroutine, which still executes deferred functions
defer func() {
cancel() // will cause runMultipleConnections() to terminate
wg.Wait()
}()

uuid := testRevertMigration(t, uuids[len(uuids)-1], ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
}()
checkMigratedTable(t, tableName, alterHints[1])
testSelectTableMetrics(t)
})
Expand All @@ -821,11 +849,20 @@ func testRevert(t *testing.T) {
defer wg.Done()
runMultipleConnections(ctx, t)
}()
uuid := testRevertMigration(t, uuids[len(uuids)-1], ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
cancel() // will cause runMultipleConnections() to terminate
wg.Wait()

func() {
// Ensures runMultipleConnections completes before the overall
// test does, even in the face of calls to t.FailNow() in the
// main goroutine, which still executes deferred functions
defer func() {
cancel() // will cause runMultipleConnections() to terminate
wg.Wait()
}()

uuid := testRevertMigration(t, uuids[len(uuids)-1], ddlStrategy)
uuids = append(uuids, uuid)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
}()
checkMigratedTable(t, tableName, alterHints[0])
testSelectTableMetrics(t)
})
Expand All @@ -839,6 +876,15 @@ func testRevert(t *testing.T) {
defer wg.Done()
runMultipleConnections(ctx, t)
}()

// Ensures runMultipleConnections completes before the overall
// test does, even in the face of calls to t.FailNow() in the
// main goroutine, which still executes deferred functions
defer func() {
cancel() // will cause runMultipleConnections() to terminate
wg.Wait()
}()

uuid := testRevertMigration(t, uuids[len(uuids)-1], ddlStrategy+" --postpone-completion")
uuids = append(uuids, uuid)
// Should be still running!
Expand All @@ -849,8 +895,6 @@ func testRevert(t *testing.T) {
status := onlineddl.WaitForMigrationStatus(t, &vtParams, shards, uuid, 60*time.Second, schema.OnlineDDLStatusComplete, schema.OnlineDDLStatusFailed)
fmt.Printf("# Migration status (for debug purposes): <%s>\n", status)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, uuid, schema.OnlineDDLStatusComplete)
cancel() // will cause runMultipleConnections() to terminate
wg.Wait()
}
t.Run("postponed revert", func(t *testing.T) {
testPostponedRevert(t, schema.OnlineDDLStatusRunning)
Expand Down
Loading