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

Flaky TestRestart: give mysqlctld process time to shutdown #12799

Merged
merged 2 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions go/test/endtoend/cluster/mysqlctld_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,8 @@ func (mysqlctld *MysqlctldProcess) IsHealthy() bool {
_, err := mysql.Connect(context.Background(), &params)
return err == nil
}

// HasShutdown checks if the process has been set to nil
func (mysqlctld *MysqlctldProcess) HasShutdown() bool {
return mysqlctld.process == nil
rohit-nayak-ps marked this conversation as resolved.
Show resolved Hide resolved
}
20 changes: 20 additions & 0 deletions go/test/endtoend/mysqlctld/mysqlctld_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"os"
"testing"
"time"

"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -134,10 +135,29 @@ func initCluster(shardNames []string, totalTabletsRequired int) error {
return nil
}

const defaultOperationTimeout = 60 * time.Second
mattlord marked this conversation as resolved.
Show resolved Hide resolved
const defeaultRetryDelay = 3 * time.Second

func waitForMysqlctldShutdown(t *testing.T, tab *cluster.Vttablet) bool {
tmr := time.NewTimer(defaultOperationTimeout)
mattlord marked this conversation as resolved.
Show resolved Hide resolved
for {
if tab.MysqlctldProcess.HasShutdown() {
return true
}
select {
case <-tmr.C:
return false
default:
}
time.Sleep(defeaultRetryDelay)
rohit-nayak-ps marked this conversation as resolved.
Show resolved Hide resolved
}
}

func TestRestart(t *testing.T) {
defer cluster.PanicHandler(t)
err := primaryTablet.MysqlctldProcess.Stop()
require.Nil(t, err)
require.Truef(t, waitForMysqlctldShutdown(t, primaryTablet), "Mysqlctld has not stopped after %s", defaultOperationTimeout)
primaryTablet.MysqlctldProcess.CleanupFiles(primaryTablet.TabletUID)
err = primaryTablet.MysqlctldProcess.Start()
require.Nil(t, err)
Expand Down