From c4e7b9611f124576ef7187644e8f884d39acbd08 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Sun, 15 Sep 2024 11:36:52 +0300 Subject: [PATCH 1/2] endtoend: better error reporting in Online DDL MySQL execution tests Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/test/endtoend/onlineddl/exec_util.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/go/test/endtoend/onlineddl/exec_util.go b/go/test/endtoend/onlineddl/exec_util.go index 95ab25ece5c..1744c58830e 100644 --- a/go/test/endtoend/onlineddl/exec_util.go +++ b/go/test/endtoend/onlineddl/exec_util.go @@ -62,6 +62,8 @@ func MysqlClientExecFile(t *testing.T, mysqlParams *mysql.ConnParams, testDataPa bashCommand, ).Output() - require.NoError(t, err) + errorContent, readerr := os.ReadFile("/tmp/error.log") + require.NoError(t, readerr) + require.NoError(t, err, "error details: %s", errorContent) return string(cmd) } From 666e231bfb6e7098b12daa2799c46e780edbeee5 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Sun, 15 Sep 2024 11:43:42 +0300 Subject: [PATCH 2/2] use temp file, make sure to delete it Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/test/endtoend/onlineddl/exec_util.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/go/test/endtoend/onlineddl/exec_util.go b/go/test/endtoend/onlineddl/exec_util.go index 1744c58830e..d86f39eb834 100644 --- a/go/test/endtoend/onlineddl/exec_util.go +++ b/go/test/endtoend/onlineddl/exec_util.go @@ -46,6 +46,10 @@ func CreateTempScript(t *testing.T, content string) (fileName string) { func MysqlClientExecFile(t *testing.T, mysqlParams *mysql.ConnParams, testDataPath, testName string, fileName string) (output string) { t.Helper() + errorFile, err := os.CreateTemp("", "onlineddl-test-") + require.NoError(t, err) + defer os.Remove(errorFile.Name()) + bashPath, err := exec.LookPath("bash") require.NoError(t, err) mysqlPath, err := exec.LookPath("mysql") @@ -55,14 +59,14 @@ func MysqlClientExecFile(t *testing.T, mysqlParams *mysql.ConnParams, testDataPa if !filepath.IsAbs(fileName) { filePath, _ = filepath.Abs(path.Join(testDataPath, testName, fileName)) } - bashCommand := fmt.Sprintf(`%s -u%s --socket=%s --database=%s -s -s < %s 2> /tmp/error.log`, mysqlPath, mysqlParams.Uname, mysqlParams.UnixSocket, mysqlParams.DbName, filePath) + bashCommand := fmt.Sprintf(`%s -u%s --socket=%s --database=%s -s -s < %s 2> %s`, mysqlPath, mysqlParams.Uname, mysqlParams.UnixSocket, mysqlParams.DbName, filePath, errorFile.Name()) cmd, err := exec.Command( bashPath, "-c", bashCommand, ).Output() - errorContent, readerr := os.ReadFile("/tmp/error.log") + errorContent, readerr := os.ReadFile(errorFile.Name()) require.NoError(t, readerr) require.NoError(t, err, "error details: %s", errorContent) return string(cmd)