From 29f86f6c556dd4a61026bd27a9000821f20e3d21 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Tue, 12 Dec 2023 23:48:27 +0900 Subject: [PATCH 01/42] Refactor test cleanup in driver_test.go --- driver_test.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/driver_test.go b/driver_test.go index 97fd5a17a..7e6cc920c 100644 --- a/driver_test.go +++ b/driver_test.go @@ -149,8 +149,9 @@ func runTests(t *testing.T, dsn string, tests ...func(dbt *DBTest)) { } defer db.Close() - // Previous test may be skipped without dropping the test table - db.Exec("DROP TABLE IF EXISTS test") + cleanup := func() { + db.Exec("DROP TABLE IF EXISTS test") + } dsn2 := dsn + "&interpolateParams=true" var db2 *sql.DB @@ -163,15 +164,16 @@ func runTests(t *testing.T, dsn string, tests ...func(dbt *DBTest)) { } for _, test := range tests { + test := test t.Run("default", func(t *testing.T) { dbt := &DBTest{t, db} - defer dbt.db.Exec("DROP TABLE IF EXISTS test") + t.Cleanup(cleanup) test(dbt) }) if db2 != nil { t.Run("interpolateParams", func(t *testing.T) { dbt2 := &DBTest{t, db2} - defer dbt2.db.Exec("DROP TABLE IF EXISTS test") + t.Cleanup(cleanup) test(dbt2) }) } From f4000b8c6ac65a2952f02185e29f972db7e33699 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:02:01 +0900 Subject: [PATCH 02/42] parallelize TestEmptyQuery and TestCRUD --- driver_test.go | 79 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 69 insertions(+), 10 deletions(-) diff --git a/driver_test.go b/driver_test.go index 7e6cc920c..3871d0e15 100644 --- a/driver_test.go +++ b/driver_test.go @@ -11,6 +11,7 @@ package mysql import ( "bytes" "context" + "crypto/rand" "crypto/tls" "database/sql" "database/sql/driver" @@ -180,6 +181,64 @@ func runTests(t *testing.T, dsn string, tests ...func(dbt *DBTest)) { } } +// runTestsParallel runs the tests in parallel with a separate database connection for each test. +func runTestsParallel(t *testing.T, dsn string, tests ...func(dbt *DBTest, tableName string)) { + if !available { + t.Skipf("MySQL server not running on %s", netAddr) + } + + newTableName := func(t *testing.T) string { + t.Helper() + var buf [8]byte + if _, err := rand.Read(buf[:]); err != nil { + t.Fatal(err) + } + return fmt.Sprintf("test_%x", buf[:]) + } + + t.Parallel() + for _, test := range tests { + test := test + + t.Run("default", func(t *testing.T) { + t.Parallel() + + tableName := newTableName(t) + db, err := sql.Open("mysql", dsn) + if err != nil { + t.Fatalf("error connecting: %s", err.Error()) + } + t.Cleanup(func() { + db.Exec("DROP TABLE IF EXISTS " + tableName) + db.Close() + }) + + dbt := &DBTest{t, db} + test(dbt, tableName) + }) + + dsn2 := dsn + "&interpolateParams=true" + if _, err := ParseDSN(dsn2); err == errInvalidDSNUnsafeCollation { + t.Run("interpolateParams", func(t *testing.T) { + t.Parallel() + + tableName := newTableName(t) + db, err := sql.Open("mysql", dsn2) + if err != nil { + t.Fatalf("error connecting: %s", err.Error()) + } + t.Cleanup(func() { + db.Exec("DROP TABLE IF EXISTS " + tableName) + db.Close() + }) + + dbt := &DBTest{t, db} + test(dbt, tableName) + }) + } + } +} + func (dbt *DBTest) fail(method, query string, err error) { dbt.Helper() if len(query) > 300 { @@ -218,7 +277,7 @@ func maybeSkip(t *testing.T, err error, skipErrno uint16) { } func TestEmptyQuery(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, _ string) { // just a comment, no query rows := dbt.mustQuery("--") defer rows.Close() @@ -230,20 +289,20 @@ func TestEmptyQuery(t *testing.T) { } func TestCRUD(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { // Create Table - dbt.mustExec("CREATE TABLE test (value BOOL)") + dbt.mustExec("CREATE TABLE " + tbl + " (value BOOL)") // Test for unexpected data var out bool - rows := dbt.mustQuery("SELECT * FROM test") + rows := dbt.mustQuery("SELECT * FROM " + tbl) if rows.Next() { dbt.Error("unexpected data in empty table") } rows.Close() // Create Data - res := dbt.mustExec("INSERT INTO test VALUES (1)") + res := dbt.mustExec("INSERT INTO " + tbl + " VALUES (1)") count, err := res.RowsAffected() if err != nil { dbt.Fatalf("res.RowsAffected() returned error: %s", err.Error()) @@ -261,7 +320,7 @@ func TestCRUD(t *testing.T) { } // Read - rows = dbt.mustQuery("SELECT value FROM test") + rows = dbt.mustQuery("SELECT value FROM " + tbl) if rows.Next() { rows.Scan(&out) if true != out { @@ -277,7 +336,7 @@ func TestCRUD(t *testing.T) { rows.Close() // Update - res = dbt.mustExec("UPDATE test SET value = ? WHERE value = ?", false, true) + res = dbt.mustExec("UPDATE "+tbl+" SET value = ? WHERE value = ?", false, true) count, err = res.RowsAffected() if err != nil { dbt.Fatalf("res.RowsAffected() returned error: %s", err.Error()) @@ -287,7 +346,7 @@ func TestCRUD(t *testing.T) { } // Check Update - rows = dbt.mustQuery("SELECT value FROM test") + rows = dbt.mustQuery("SELECT value FROM " + tbl) if rows.Next() { rows.Scan(&out) if false != out { @@ -303,7 +362,7 @@ func TestCRUD(t *testing.T) { rows.Close() // Delete - res = dbt.mustExec("DELETE FROM test WHERE value = ?", false) + res = dbt.mustExec("DELETE FROM "+tbl+" WHERE value = ?", false) count, err = res.RowsAffected() if err != nil { dbt.Fatalf("res.RowsAffected() returned error: %s", err.Error()) @@ -313,7 +372,7 @@ func TestCRUD(t *testing.T) { } // Check for unexpected rows - res = dbt.mustExec("DELETE FROM test") + res = dbt.mustExec("DELETE FROM " + tbl) count, err = res.RowsAffected() if err != nil { dbt.Fatalf("res.RowsAffected() returned error: %s", err.Error()) From f49d8d69eff693a9f06ae7034cb75fd843bc41d0 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:06:05 +0900 Subject: [PATCH 03/42] parallelize TestNumbersToAny --- driver_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/driver_test.go b/driver_test.go index 3871d0e15..3ea7a0cb2 100644 --- a/driver_test.go +++ b/driver_test.go @@ -386,13 +386,13 @@ func TestCRUD(t *testing.T) { // TestNumbers test that selecting numeric columns. // Both of textRows and binaryRows should return same type and value. func TestNumbersToAny(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { - dbt.mustExec("CREATE TABLE `test` (id INT PRIMARY KEY, b BOOL, i8 TINYINT, " + + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { + dbt.mustExec("CREATE TABLE " + tbl + " (id INT PRIMARY KEY, b BOOL, i8 TINYINT, " + "i16 SMALLINT, i32 INT, i64 BIGINT, f32 FLOAT, f64 DOUBLE)") - dbt.mustExec("INSERT INTO `test` VALUES (1, true, 127, 32767, 2147483647, 9223372036854775807, 1.25, 2.5)") + dbt.mustExec("INSERT INTO " + tbl + " VALUES (1, true, 127, 32767, 2147483647, 9223372036854775807, 1.25, 2.5)") // Use binaryRows for intarpolateParams=false and textRows for intarpolateParams=true. - rows := dbt.mustQuery("SELECT b, i8, i16, i32, i64, f32, f64 FROM `test` WHERE id=?", 1) + rows := dbt.mustQuery("SELECT b, i8, i16, i32, i64, f32, f64 FROM "+tbl+" WHERE id=?", 1) if !rows.Next() { dbt.Fatal("no data") } From 7b9d72095c36b004021df2e883fa0070cb262df3 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:08:22 +0900 Subject: [PATCH 04/42] parallelize TestInt --- driver_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/driver_test.go b/driver_test.go index 3ea7a0cb2..d1db51375 100644 --- a/driver_test.go +++ b/driver_test.go @@ -471,7 +471,7 @@ func TestMultiQuery(t *testing.T) { } func TestInt(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { types := [5]string{"TINYINT", "SMALLINT", "MEDIUMINT", "INT", "BIGINT"} in := int64(42) var out int64 @@ -479,11 +479,11 @@ func TestInt(t *testing.T) { // SIGNED for _, v := range types { - dbt.mustExec("CREATE TABLE test (value " + v + ")") + dbt.mustExec("CREATE TABLE " + tbl + " (value " + v + ")") - dbt.mustExec("INSERT INTO test VALUES (?)", in) + dbt.mustExec("INSERT INTO "+tbl+" VALUES (?)", in) - rows = dbt.mustQuery("SELECT value FROM test") + rows = dbt.mustQuery("SELECT value FROM " + tbl) if rows.Next() { rows.Scan(&out) if in != out { @@ -494,16 +494,16 @@ func TestInt(t *testing.T) { } rows.Close() - dbt.mustExec("DROP TABLE IF EXISTS test") + dbt.mustExec("DROP TABLE IF EXISTS " + tbl) } // UNSIGNED ZEROFILL for _, v := range types { - dbt.mustExec("CREATE TABLE test (value " + v + " ZEROFILL)") + dbt.mustExec("CREATE TABLE " + tbl + " (value " + v + " ZEROFILL)") - dbt.mustExec("INSERT INTO test VALUES (?)", in) + dbt.mustExec("INSERT INTO "+tbl+" VALUES (?)", in) - rows = dbt.mustQuery("SELECT value FROM test") + rows = dbt.mustQuery("SELECT value FROM " + tbl) if rows.Next() { rows.Scan(&out) if in != out { @@ -514,7 +514,7 @@ func TestInt(t *testing.T) { } rows.Close() - dbt.mustExec("DROP TABLE IF EXISTS test") + dbt.mustExec("DROP TABLE IF EXISTS " + tbl) } }) } From d4c6d67f58818d2a55b4fe666891e937c83231f3 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:09:42 +0900 Subject: [PATCH 05/42] parallelize TestFloat32 --- driver_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/driver_test.go b/driver_test.go index d1db51375..f9883ea36 100644 --- a/driver_test.go +++ b/driver_test.go @@ -520,15 +520,15 @@ func TestInt(t *testing.T) { } func TestFloat32(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { types := [2]string{"FLOAT", "DOUBLE"} in := float32(42.23) var out float32 var rows *sql.Rows for _, v := range types { - dbt.mustExec("CREATE TABLE test (value " + v + ")") - dbt.mustExec("INSERT INTO test VALUES (?)", in) - rows = dbt.mustQuery("SELECT value FROM test") + dbt.mustExec("CREATE TABLE " + tbl + " (value " + v + ")") + dbt.mustExec("INSERT INTO "+tbl+" VALUES (?)", in) + rows = dbt.mustQuery("SELECT value FROM " + tbl) if rows.Next() { rows.Scan(&out) if in != out { @@ -538,7 +538,7 @@ func TestFloat32(t *testing.T) { dbt.Errorf("%s: no data", v) } rows.Close() - dbt.mustExec("DROP TABLE IF EXISTS test") + dbt.mustExec("DROP TABLE IF EXISTS " + tbl) } }) } From d1f38febe70a78659ef43c49594160eb303ac635 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:12:52 +0900 Subject: [PATCH 06/42] parallelize TestFloat64 --- driver_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/driver_test.go b/driver_test.go index f9883ea36..c2166d034 100644 --- a/driver_test.go +++ b/driver_test.go @@ -544,15 +544,15 @@ func TestFloat32(t *testing.T) { } func TestFloat64(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { types := [2]string{"FLOAT", "DOUBLE"} var expected float64 = 42.23 var out float64 var rows *sql.Rows for _, v := range types { - dbt.mustExec("CREATE TABLE test (value " + v + ")") - dbt.mustExec("INSERT INTO test VALUES (42.23)") - rows = dbt.mustQuery("SELECT value FROM test") + dbt.mustExec("CREATE TABLE " + tbl + " (value " + v + ")") + dbt.mustExec("INSERT INTO " + tbl + " VALUES (42.23)") + rows = dbt.mustQuery("SELECT value FROM " + tbl) if rows.Next() { rows.Scan(&out) if expected != out { @@ -562,7 +562,7 @@ func TestFloat64(t *testing.T) { dbt.Errorf("%s: no data", v) } rows.Close() - dbt.mustExec("DROP TABLE IF EXISTS test") + dbt.mustExec("DROP TABLE IF EXISTS " + tbl) } }) } From 7845ed92600e4f33f35faf8bf250813f3fa5d863 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:16:37 +0900 Subject: [PATCH 07/42] parallelize TestFloat64Placeholder --- driver_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/driver_test.go b/driver_test.go index c2166d034..2c08c51a1 100644 --- a/driver_test.go +++ b/driver_test.go @@ -568,15 +568,15 @@ func TestFloat64(t *testing.T) { } func TestFloat64Placeholder(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { types := [2]string{"FLOAT", "DOUBLE"} var expected float64 = 42.23 var out float64 var rows *sql.Rows for _, v := range types { - dbt.mustExec("CREATE TABLE test (id int, value " + v + ")") - dbt.mustExec("INSERT INTO test VALUES (1, 42.23)") - rows = dbt.mustQuery("SELECT value FROM test WHERE id = ?", 1) + dbt.mustExec("CREATE TABLE " + tbl + " (id int, value " + v + ")") + dbt.mustExec("INSERT INTO " + tbl + " VALUES (1, 42.23)") + rows = dbt.mustQuery("SELECT value FROM "+tbl+" WHERE id = ?", 1) if rows.Next() { rows.Scan(&out) if expected != out { @@ -586,7 +586,7 @@ func TestFloat64Placeholder(t *testing.T) { dbt.Errorf("%s: no data", v) } rows.Close() - dbt.mustExec("DROP TABLE IF EXISTS test") + dbt.mustExec("DROP TABLE IF EXISTS " + tbl) } }) } From 2a45b17e2a89e94fb1581676fe5a21bedc65bb40 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:19:15 +0900 Subject: [PATCH 08/42] parallelize TestString --- driver_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/driver_test.go b/driver_test.go index 2c08c51a1..8372115f2 100644 --- a/driver_test.go +++ b/driver_test.go @@ -592,18 +592,18 @@ func TestFloat64Placeholder(t *testing.T) { } func TestString(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { types := [6]string{"CHAR(255)", "VARCHAR(255)", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT"} in := "κόσμε üöäßñóùéàâÿœ'îë Árvíztűrő いろはにほへとちりぬるを イロハニホヘト דג סקרן чащах น่าฟังเอย" var out string var rows *sql.Rows for _, v := range types { - dbt.mustExec("CREATE TABLE test (value " + v + ") CHARACTER SET utf8") + dbt.mustExec("CREATE TABLE " + tbl + " (value " + v + ") CHARACTER SET utf8") - dbt.mustExec("INSERT INTO test VALUES (?)", in) + dbt.mustExec("INSERT INTO "+tbl+" VALUES (?)", in) - rows = dbt.mustQuery("SELECT value FROM test") + rows = dbt.mustQuery("SELECT value FROM " + tbl) if rows.Next() { rows.Scan(&out) if in != out { @@ -614,11 +614,11 @@ func TestString(t *testing.T) { } rows.Close() - dbt.mustExec("DROP TABLE IF EXISTS test") + dbt.mustExec("DROP TABLE IF EXISTS " + tbl) } // BLOB - dbt.mustExec("CREATE TABLE test (id int, value BLOB) CHARACTER SET utf8") + dbt.mustExec("CREATE TABLE " + tbl + " (id int, value BLOB) CHARACTER SET utf8") id := 2 in = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, " + @@ -629,9 +629,9 @@ func TestString(t *testing.T) { "sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, " + "sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. " + "Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet." - dbt.mustExec("INSERT INTO test VALUES (?, ?)", id, in) + dbt.mustExec("INSERT INTO "+tbl+" VALUES (?, ?)", id, in) - err := dbt.db.QueryRow("SELECT value FROM test WHERE id = ?", id).Scan(&out) + err := dbt.db.QueryRow("SELECT value FROM "+tbl+" WHERE id = ?", id).Scan(&out) if err != nil { dbt.Fatalf("Error on BLOB-Query: %s", err.Error()) } else if out != in { From 51cd376f66b97db5ce08d208cdd5bb04cc8de49c Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:20:21 +0900 Subject: [PATCH 09/42] parallelize TestRawBytes --- driver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver_test.go b/driver_test.go index 8372115f2..da12166b8 100644 --- a/driver_test.go +++ b/driver_test.go @@ -641,7 +641,7 @@ func TestString(t *testing.T) { } func TestRawBytes(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, _ string) { v1 := []byte("aaa") v2 := []byte("bbb") rows := dbt.mustQuery("SELECT ?, ?", v1, v2) From 9fd81fd2f5285fb7e6e994ca0d0f7532f6ad78ce Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:20:40 +0900 Subject: [PATCH 10/42] parallelize TestRawMessage --- driver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver_test.go b/driver_test.go index da12166b8..6816efb1f 100644 --- a/driver_test.go +++ b/driver_test.go @@ -670,7 +670,7 @@ func TestRawBytes(t *testing.T) { } func TestRawMessage(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, _ string) { v1 := json.RawMessage("{}") v2 := json.RawMessage("[]") rows := dbt.mustQuery("SELECT ?, ?", v1, v2) From b0de07f846a15a2071cb2087fdf76536a005745f Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:22:17 +0900 Subject: [PATCH 11/42] parallelize TestValuer --- driver_test.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/driver_test.go b/driver_test.go index 6816efb1f..a6d488cb4 100644 --- a/driver_test.go +++ b/driver_test.go @@ -701,14 +701,14 @@ func (tv testValuer) Value() (driver.Value, error) { } func TestValuer(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { in := testValuer{"a_value"} var out string var rows *sql.Rows - dbt.mustExec("CREATE TABLE test (value VARCHAR(255)) CHARACTER SET utf8") - dbt.mustExec("INSERT INTO test VALUES (?)", in) - rows = dbt.mustQuery("SELECT value FROM test") + dbt.mustExec("CREATE TABLE " + tbl + " (value VARCHAR(255)) CHARACTER SET utf8") + dbt.mustExec("INSERT INTO "+tbl+" VALUES (?)", in) + rows = dbt.mustQuery("SELECT value FROM " + tbl) if rows.Next() { rows.Scan(&out) if in.value != out { @@ -718,8 +718,6 @@ func TestValuer(t *testing.T) { dbt.Errorf("Valuer: no data") } rows.Close() - - dbt.mustExec("DROP TABLE IF EXISTS test") }) } From daa5b3890520aa7e8b2123269916604894ce0da4 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:23:41 +0900 Subject: [PATCH 12/42] parallelize TestValuerWithValidation --- driver_test.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/driver_test.go b/driver_test.go index a6d488cb4..68343f08f 100644 --- a/driver_test.go +++ b/driver_test.go @@ -734,15 +734,15 @@ func (tv testValuerWithValidation) Value() (driver.Value, error) { } func TestValuerWithValidation(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { in := testValuerWithValidation{"a_value"} var out string var rows *sql.Rows - dbt.mustExec("CREATE TABLE testValuer (value VARCHAR(255)) CHARACTER SET utf8") - dbt.mustExec("INSERT INTO testValuer VALUES (?)", in) + dbt.mustExec("CREATE TABLE " + tbl + " (value VARCHAR(255)) CHARACTER SET utf8") + dbt.mustExec("INSERT INTO "+tbl+" VALUES (?)", in) - rows = dbt.mustQuery("SELECT value FROM testValuer") + rows = dbt.mustQuery("SELECT value FROM " + tbl) defer rows.Close() if rows.Next() { @@ -754,19 +754,17 @@ func TestValuerWithValidation(t *testing.T) { dbt.Errorf("Valuer: no data") } - if _, err := dbt.db.Exec("INSERT INTO testValuer VALUES (?)", testValuerWithValidation{""}); err == nil { + if _, err := dbt.db.Exec("INSERT INTO "+tbl+" VALUES (?)", testValuerWithValidation{""}); err == nil { dbt.Errorf("Failed to check valuer error") } - if _, err := dbt.db.Exec("INSERT INTO testValuer VALUES (?)", nil); err != nil { + if _, err := dbt.db.Exec("INSERT INTO "+tbl+" VALUES (?)", nil); err != nil { dbt.Errorf("Failed to check nil") } - if _, err := dbt.db.Exec("INSERT INTO testValuer VALUES (?)", map[string]bool{}); err == nil { + if _, err := dbt.db.Exec("INSERT INTO "+tbl+" VALUES (?)", map[string]bool{}); err == nil { dbt.Errorf("Failed to check not valuer") } - - dbt.mustExec("DROP TABLE IF EXISTS testValuer") }) } From 082c897aa0cdb7f69d21ffec5de90f710274c1fe Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:25:23 +0900 Subject: [PATCH 13/42] parallelize TestTimestampMicros --- driver_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/driver_test.go b/driver_test.go index 68343f08f..020098507 100644 --- a/driver_test.go +++ b/driver_test.go @@ -998,7 +998,7 @@ func TestTimestampMicros(t *testing.T) { f0 := format[:19] f1 := format[:21] f6 := format[:26] - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { // check if microseconds are supported. // Do not use timestamp(x) for that check - before 5.5.6, x would mean display width // and not precision. @@ -1013,7 +1013,7 @@ func TestTimestampMicros(t *testing.T) { return } _, err := dbt.db.Exec(` - CREATE TABLE test ( + CREATE TABLE ` + tbl + ` ( value0 TIMESTAMP NOT NULL DEFAULT '` + f0 + `', value1 TIMESTAMP(1) NOT NULL DEFAULT '` + f1 + `', value6 TIMESTAMP(6) NOT NULL DEFAULT '` + f6 + `' @@ -1022,10 +1022,10 @@ func TestTimestampMicros(t *testing.T) { if err != nil { dbt.Error(err) } - defer dbt.mustExec("DROP TABLE IF EXISTS test") - dbt.mustExec("INSERT INTO test SET value0=?, value1=?, value6=?", f0, f1, f6) + defer dbt.mustExec("DROP TABLE IF EXISTS " + tbl) + dbt.mustExec("INSERT INTO "+tbl+" SET value0=?, value1=?, value6=?", f0, f1, f6) var res0, res1, res6 string - rows := dbt.mustQuery("SELECT * FROM test") + rows := dbt.mustQuery("SELECT * FROM " + tbl) defer rows.Close() if !rows.Next() { dbt.Errorf("test contained no selectable values") From a93288377ee81e85628676370e142b4e1b2bebfa Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:26:49 +0900 Subject: [PATCH 14/42] parallelize TestNULL --- driver_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/driver_test.go b/driver_test.go index 020098507..a72a165f5 100644 --- a/driver_test.go +++ b/driver_test.go @@ -1047,7 +1047,7 @@ func TestTimestampMicros(t *testing.T) { } func TestNULL(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { nullStmt, err := dbt.db.Prepare("SELECT NULL") if err != nil { dbt.Fatal(err) @@ -1179,12 +1179,12 @@ func TestNULL(t *testing.T) { } // Insert NULL - dbt.mustExec("CREATE TABLE test (dummmy1 int, value int, dummy2 int)") + dbt.mustExec("CREATE TABLE " + tbl + " (dummmy1 int, value int, dummy2 int)") - dbt.mustExec("INSERT INTO test VALUES (?, ?, ?)", 1, nil, 2) + dbt.mustExec("INSERT INTO "+tbl+" VALUES (?, ?, ?)", 1, nil, 2) var out interface{} - rows := dbt.mustQuery("SELECT * FROM test") + rows := dbt.mustQuery("SELECT * FROM " + tbl) defer rows.Close() if rows.Next() { rows.Scan(&out) From 2242274abe8f27f8939780d0f3e7642e2221d6b9 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:27:51 +0900 Subject: [PATCH 15/42] parallelize TestUint64 --- driver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver_test.go b/driver_test.go index a72a165f5..45680e8b0 100644 --- a/driver_test.go +++ b/driver_test.go @@ -1208,7 +1208,7 @@ func TestUint64(t *testing.T) { shigh = int64(uhigh) stop = ^shigh ) - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, _ string) { stmt, err := dbt.db.Prepare(`SELECT ?, ?, ? ,?, ?, ?, ?, ?`) if err != nil { dbt.Fatal(err) From a360be7a110bb6372bed8cf7bc467e3c2dae3c66 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:29:15 +0900 Subject: [PATCH 16/42] parallelize TestLongData --- driver_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/driver_test.go b/driver_test.go index 45680e8b0..46ec70896 100644 --- a/driver_test.go +++ b/driver_test.go @@ -1241,7 +1241,7 @@ func TestUint64(t *testing.T) { } func TestLongData(t *testing.T) { - runTests(t, dsn+"&maxAllowedPacket=0", func(dbt *DBTest) { + runTestsParallel(t, dsn+"&maxAllowedPacket=0", func(dbt *DBTest, tbl string) { var maxAllowedPacketSize int err := dbt.db.QueryRow("select @@max_allowed_packet").Scan(&maxAllowedPacketSize) if err != nil { @@ -1254,7 +1254,7 @@ func TestLongData(t *testing.T) { maxAllowedPacketSize = 1 << 25 } - dbt.mustExec("CREATE TABLE test (value LONGBLOB)") + dbt.mustExec("CREATE TABLE " + tbl + " (value LONGBLOB)") in := strings.Repeat(`a`, maxAllowedPacketSize+1) var out string @@ -1263,8 +1263,8 @@ func TestLongData(t *testing.T) { // Long text data const nonDataQueryLen = 28 // length query w/o value inS := in[:maxAllowedPacketSize-nonDataQueryLen] - dbt.mustExec("INSERT INTO test VALUES('" + inS + "')") - rows = dbt.mustQuery("SELECT value FROM test") + dbt.mustExec("INSERT INTO " + tbl + " VALUES('" + inS + "')") + rows = dbt.mustQuery("SELECT value FROM " + tbl) defer rows.Close() if rows.Next() { rows.Scan(&out) @@ -1279,11 +1279,11 @@ func TestLongData(t *testing.T) { } // Empty table - dbt.mustExec("TRUNCATE TABLE test") + dbt.mustExec("TRUNCATE TABLE " + tbl) // Long binary data - dbt.mustExec("INSERT INTO test VALUES(?)", in) - rows = dbt.mustQuery("SELECT value FROM test WHERE 1=?", 1) + dbt.mustExec("INSERT INTO "+tbl+" VALUES(?)", in) + rows = dbt.mustQuery("SELECT value FROM "+tbl+" WHERE 1=?", 1) defer rows.Close() if rows.Next() { rows.Scan(&out) From 01f85bafe1929d30b39ba66491838244473ff4c1 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:32:35 +0900 Subject: [PATCH 17/42] parallelize TestContextCancelExec --- driver_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/driver_test.go b/driver_test.go index 46ec70896..e6450b21f 100644 --- a/driver_test.go +++ b/driver_test.go @@ -2629,8 +2629,8 @@ func TestPingContext(t *testing.T) { } func TestContextCancelExec(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { - dbt.mustExec("CREATE TABLE test (v INTEGER)") + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { + dbt.mustExec("CREATE TABLE " + tbl + " (v INTEGER)") ctx, cancel := context.WithCancel(context.Background()) // Delay execution for just a bit until db.ExecContext has begun. @@ -2638,7 +2638,7 @@ func TestContextCancelExec(t *testing.T) { // This query will be canceled. startTime := time.Now() - if _, err := dbt.db.ExecContext(ctx, "INSERT INTO test VALUES (SLEEP(1))"); err != context.Canceled { + if _, err := dbt.db.ExecContext(ctx, "INSERT INTO "+tbl+" VALUES (SLEEP(1))"); err != context.Canceled { dbt.Errorf("expected context.Canceled, got %v", err) } if d := time.Since(startTime); d > 500*time.Millisecond { @@ -2650,7 +2650,7 @@ func TestContextCancelExec(t *testing.T) { // Check how many times the query is executed. var v int - if err := dbt.db.QueryRow("SELECT COUNT(*) FROM test").Scan(&v); err != nil { + if err := dbt.db.QueryRow("SELECT COUNT(*) FROM " + tbl).Scan(&v); err != nil { dbt.Fatalf("%s", err.Error()) } if v != 1 { // TODO: need to kill the query, and v should be 0. @@ -2658,14 +2658,14 @@ func TestContextCancelExec(t *testing.T) { } // Context is already canceled, so error should come before execution. - if _, err := dbt.db.ExecContext(ctx, "INSERT INTO test VALUES (1)"); err == nil { + if _, err := dbt.db.ExecContext(ctx, "INSERT INTO "+tbl+" VALUES (1)"); err == nil { dbt.Error("expected error") } else if err.Error() != "context canceled" { dbt.Fatalf("unexpected error: %s", err) } // The second insert query will fail, so the table has no changes. - if err := dbt.db.QueryRow("SELECT COUNT(*) FROM test").Scan(&v); err != nil { + if err := dbt.db.QueryRow("SELECT COUNT(*) FROM " + tbl).Scan(&v); err != nil { dbt.Fatalf("%s", err.Error()) } if v != 1 { From 06c953a8ef353a798b933edd7be4e32f50663bc2 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:33:01 +0900 Subject: [PATCH 18/42] parallelize TestPingContext --- driver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver_test.go b/driver_test.go index e6450b21f..e2086f034 100644 --- a/driver_test.go +++ b/driver_test.go @@ -2619,7 +2619,7 @@ func TestQueryMultipleResults(t *testing.T) { } func TestPingContext(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, _ string) { ctx, cancel := context.WithCancel(context.Background()) cancel() if err := dbt.db.PingContext(ctx); err != context.Canceled { From 3deb8b4879a591c1fac0e04007e49d60f9d20c06 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:34:06 +0900 Subject: [PATCH 19/42] parallelize TestContextCancelQuery --- driver_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/driver_test.go b/driver_test.go index e2086f034..aafaeeb8e 100644 --- a/driver_test.go +++ b/driver_test.go @@ -2675,8 +2675,8 @@ func TestContextCancelExec(t *testing.T) { } func TestContextCancelQuery(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { - dbt.mustExec("CREATE TABLE test (v INTEGER)") + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { + dbt.mustExec("CREATE TABLE " + tbl + " (v INTEGER)") ctx, cancel := context.WithCancel(context.Background()) // Delay execution for just a bit until db.ExecContext has begun. @@ -2684,7 +2684,7 @@ func TestContextCancelQuery(t *testing.T) { // This query will be canceled. startTime := time.Now() - if _, err := dbt.db.QueryContext(ctx, "INSERT INTO test VALUES (SLEEP(1))"); err != context.Canceled { + if _, err := dbt.db.QueryContext(ctx, "INSERT INTO "+tbl+" VALUES (SLEEP(1))"); err != context.Canceled { dbt.Errorf("expected context.Canceled, got %v", err) } if d := time.Since(startTime); d > 500*time.Millisecond { @@ -2696,7 +2696,7 @@ func TestContextCancelQuery(t *testing.T) { // Check how many times the query is executed. var v int - if err := dbt.db.QueryRow("SELECT COUNT(*) FROM test").Scan(&v); err != nil { + if err := dbt.db.QueryRow("SELECT COUNT(*) FROM " + tbl).Scan(&v); err != nil { dbt.Fatalf("%s", err.Error()) } if v != 1 { // TODO: need to kill the query, and v should be 0. @@ -2704,12 +2704,12 @@ func TestContextCancelQuery(t *testing.T) { } // Context is already canceled, so error should come before execution. - if _, err := dbt.db.QueryContext(ctx, "INSERT INTO test VALUES (1)"); err != context.Canceled { + if _, err := dbt.db.QueryContext(ctx, "INSERT INTO "+tbl+" VALUES (1)"); err != context.Canceled { dbt.Errorf("expected context.Canceled, got %v", err) } // The second insert query will fail, so the table has no changes. - if err := dbt.db.QueryRow("SELECT COUNT(*) FROM test").Scan(&v); err != nil { + if err := dbt.db.QueryRow("SELECT COUNT(*) FROM " + tbl).Scan(&v); err != nil { dbt.Fatalf("%s", err.Error()) } if v != 1 { From f69130a704f26773d35e24d8a54fe89e951cabdb Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:35:25 +0900 Subject: [PATCH 20/42] parallelize TestContextCancelQueryRow --- driver_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/driver_test.go b/driver_test.go index aafaeeb8e..5d604ad77 100644 --- a/driver_test.go +++ b/driver_test.go @@ -2719,12 +2719,12 @@ func TestContextCancelQuery(t *testing.T) { } func TestContextCancelQueryRow(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { - dbt.mustExec("CREATE TABLE test (v INTEGER)") - dbt.mustExec("INSERT INTO test VALUES (1), (2), (3)") + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { + dbt.mustExec("CREATE TABLE " + tbl + " (v INTEGER)") + dbt.mustExec("INSERT INTO " + tbl + " VALUES (1), (2), (3)") ctx, cancel := context.WithCancel(context.Background()) - rows, err := dbt.db.QueryContext(ctx, "SELECT v FROM test") + rows, err := dbt.db.QueryContext(ctx, "SELECT v FROM "+tbl) if err != nil { dbt.Fatalf("%s", err.Error()) } From dfef6a0784d1cdefa916d73686663e65b180b2af Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:37:07 +0900 Subject: [PATCH 21/42] Revert "parallelize TestLongData" This reverts commit a360be7a110bb6372bed8cf7bc467e3c2dae3c66. --- driver_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/driver_test.go b/driver_test.go index 5d604ad77..d60a3d4cf 100644 --- a/driver_test.go +++ b/driver_test.go @@ -1241,7 +1241,7 @@ func TestUint64(t *testing.T) { } func TestLongData(t *testing.T) { - runTestsParallel(t, dsn+"&maxAllowedPacket=0", func(dbt *DBTest, tbl string) { + runTests(t, dsn+"&maxAllowedPacket=0", func(dbt *DBTest) { var maxAllowedPacketSize int err := dbt.db.QueryRow("select @@max_allowed_packet").Scan(&maxAllowedPacketSize) if err != nil { @@ -1254,7 +1254,7 @@ func TestLongData(t *testing.T) { maxAllowedPacketSize = 1 << 25 } - dbt.mustExec("CREATE TABLE " + tbl + " (value LONGBLOB)") + dbt.mustExec("CREATE TABLE test (value LONGBLOB)") in := strings.Repeat(`a`, maxAllowedPacketSize+1) var out string @@ -1263,8 +1263,8 @@ func TestLongData(t *testing.T) { // Long text data const nonDataQueryLen = 28 // length query w/o value inS := in[:maxAllowedPacketSize-nonDataQueryLen] - dbt.mustExec("INSERT INTO " + tbl + " VALUES('" + inS + "')") - rows = dbt.mustQuery("SELECT value FROM " + tbl) + dbt.mustExec("INSERT INTO test VALUES('" + inS + "')") + rows = dbt.mustQuery("SELECT value FROM test") defer rows.Close() if rows.Next() { rows.Scan(&out) @@ -1279,11 +1279,11 @@ func TestLongData(t *testing.T) { } // Empty table - dbt.mustExec("TRUNCATE TABLE " + tbl) + dbt.mustExec("TRUNCATE TABLE test") // Long binary data - dbt.mustExec("INSERT INTO "+tbl+" VALUES(?)", in) - rows = dbt.mustQuery("SELECT value FROM "+tbl+" WHERE 1=?", 1) + dbt.mustExec("INSERT INTO test VALUES(?)", in) + rows = dbt.mustQuery("SELECT value FROM test WHERE 1=?", 1) defer rows.Close() if rows.Next() { rows.Scan(&out) From c9febfc14b92231b491c449fd8ef5bb00be01bf0 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:39:13 +0900 Subject: [PATCH 22/42] parallelize TestContextCancelPrepare --- driver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver_test.go b/driver_test.go index d60a3d4cf..1355d79a3 100644 --- a/driver_test.go +++ b/driver_test.go @@ -2752,7 +2752,7 @@ func TestContextCancelQueryRow(t *testing.T) { } func TestContextCancelPrepare(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, _ string) { ctx, cancel := context.WithCancel(context.Background()) cancel() if _, err := dbt.db.PrepareContext(ctx, "SELECT 1"); err != context.Canceled { From 18dca94a0da90e2d354cc620ebf82ebf08a43290 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:40:18 +0900 Subject: [PATCH 23/42] parallelize TestContextCancelStmtExec --- driver_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/driver_test.go b/driver_test.go index 1355d79a3..482797c27 100644 --- a/driver_test.go +++ b/driver_test.go @@ -2762,10 +2762,10 @@ func TestContextCancelPrepare(t *testing.T) { } func TestContextCancelStmtExec(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { - dbt.mustExec("CREATE TABLE test (v INTEGER)") + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { + dbt.mustExec("CREATE TABLE " + tbl + " (v INTEGER)") ctx, cancel := context.WithCancel(context.Background()) - stmt, err := dbt.db.PrepareContext(ctx, "INSERT INTO test VALUES (SLEEP(1))") + stmt, err := dbt.db.PrepareContext(ctx, "INSERT INTO "+tbl+" VALUES (SLEEP(1))") if err != nil { dbt.Fatalf("unexpected error: %v", err) } @@ -2787,7 +2787,7 @@ func TestContextCancelStmtExec(t *testing.T) { // Check how many times the query is executed. var v int - if err := dbt.db.QueryRow("SELECT COUNT(*) FROM test").Scan(&v); err != nil { + if err := dbt.db.QueryRow("SELECT COUNT(*) FROM " + tbl).Scan(&v); err != nil { dbt.Fatalf("%s", err.Error()) } if v != 1 { // TODO: need to kill the query, and v should be 0. From 5a670dcf498a15b56b0ae76c82418ed291fb9c7e Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:41:29 +0900 Subject: [PATCH 24/42] parallelize TestContextCancelStmtQuery --- driver_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/driver_test.go b/driver_test.go index 482797c27..60a70266b 100644 --- a/driver_test.go +++ b/driver_test.go @@ -2797,10 +2797,10 @@ func TestContextCancelStmtExec(t *testing.T) { } func TestContextCancelStmtQuery(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { - dbt.mustExec("CREATE TABLE test (v INTEGER)") + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { + dbt.mustExec("CREATE TABLE " + tbl + " (v INTEGER)") ctx, cancel := context.WithCancel(context.Background()) - stmt, err := dbt.db.PrepareContext(ctx, "INSERT INTO test VALUES (SLEEP(1))") + stmt, err := dbt.db.PrepareContext(ctx, "INSERT INTO "+tbl+" VALUES (SLEEP(1))") if err != nil { dbt.Fatalf("unexpected error: %v", err) } @@ -2822,7 +2822,7 @@ func TestContextCancelStmtQuery(t *testing.T) { // Check how many times the query is executed. var v int - if err := dbt.db.QueryRow("SELECT COUNT(*) FROM test").Scan(&v); err != nil { + if err := dbt.db.QueryRow("SELECT COUNT(*) FROM " + tbl).Scan(&v); err != nil { dbt.Fatalf("%s", err.Error()) } if v != 1 { // TODO: need to kill the query, and v should be 0. From 7af63b5ee2842ea3d34d6d38ebc3767f99423e0a Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:42:29 +0900 Subject: [PATCH 25/42] parallelize TestContextCancelBegin --- driver_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/driver_test.go b/driver_test.go index 60a70266b..42c37b85a 100644 --- a/driver_test.go +++ b/driver_test.go @@ -2836,8 +2836,8 @@ func TestContextCancelBegin(t *testing.T) { t.Skip(`FIXME: it sometime fails with "expected driver.ErrBadConn, got sql: connection is already closed" on windows and macOS`) } - runTests(t, dsn, func(dbt *DBTest) { - dbt.mustExec("CREATE TABLE test (v INTEGER)") + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { + dbt.mustExec("CREATE TABLE " + tbl + " (v INTEGER)") ctx, cancel := context.WithCancel(context.Background()) conn, err := dbt.db.Conn(ctx) if err != nil { @@ -2854,7 +2854,7 @@ func TestContextCancelBegin(t *testing.T) { // This query will be canceled. startTime := time.Now() - if _, err := tx.ExecContext(ctx, "INSERT INTO test VALUES (SLEEP(1))"); err != context.Canceled { + if _, err := tx.ExecContext(ctx, "INSERT INTO "+tbl+" VALUES (SLEEP(1))"); err != context.Canceled { dbt.Errorf("expected context.Canceled, got %v", err) } if d := time.Since(startTime); d > 500*time.Millisecond { From d7650a18a5849c53ad09ea40c22420ce42618a59 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:44:21 +0900 Subject: [PATCH 26/42] parallelize TestContextBeginIsolationLevel --- driver_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/driver_test.go b/driver_test.go index 42c37b85a..187a9f7f9 100644 --- a/driver_test.go +++ b/driver_test.go @@ -2892,8 +2892,8 @@ func TestContextCancelBegin(t *testing.T) { } func TestContextBeginIsolationLevel(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { - dbt.mustExec("CREATE TABLE test (v INTEGER)") + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { + dbt.mustExec("CREATE TABLE " + tbl + " (v INTEGER)") ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -2911,13 +2911,13 @@ func TestContextBeginIsolationLevel(t *testing.T) { dbt.Fatal(err) } - _, err = tx1.ExecContext(ctx, "INSERT INTO test VALUES (1)") + _, err = tx1.ExecContext(ctx, "INSERT INTO "+tbl+" VALUES (1)") if err != nil { dbt.Fatal(err) } var v int - row := tx2.QueryRowContext(ctx, "SELECT COUNT(*) FROM test") + row := tx2.QueryRowContext(ctx, "SELECT COUNT(*) FROM "+tbl) if err := row.Scan(&v); err != nil { dbt.Fatal(err) } @@ -2931,7 +2931,7 @@ func TestContextBeginIsolationLevel(t *testing.T) { dbt.Fatal(err) } - row = tx2.QueryRowContext(ctx, "SELECT COUNT(*) FROM test") + row = tx2.QueryRowContext(ctx, "SELECT COUNT(*) FROM "+tbl) if err := row.Scan(&v); err != nil { dbt.Fatal(err) } From 5e17499b0f139d472a212a5c61a943f71f71732e Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:46:05 +0900 Subject: [PATCH 27/42] parallelize TestContextBeginReadOnly --- driver_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/driver_test.go b/driver_test.go index 187a9f7f9..8f8872446 100644 --- a/driver_test.go +++ b/driver_test.go @@ -2944,8 +2944,8 @@ func TestContextBeginIsolationLevel(t *testing.T) { } func TestContextBeginReadOnly(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { - dbt.mustExec("CREATE TABLE test (v INTEGER)") + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { + dbt.mustExec("CREATE TABLE " + tbl + " (v INTEGER)") ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -2960,14 +2960,14 @@ func TestContextBeginReadOnly(t *testing.T) { } // INSERT queries fail in a READ ONLY transaction. - _, err = tx.ExecContext(ctx, "INSERT INTO test VALUES (1)") + _, err = tx.ExecContext(ctx, "INSERT INTO "+tbl+" VALUES (1)") if _, ok := err.(*MySQLError); !ok { dbt.Errorf("expected MySQLError, got %v", err) } // SELECT queries can be executed. var v int - row := tx.QueryRowContext(ctx, "SELECT COUNT(*) FROM test") + row := tx.QueryRowContext(ctx, "SELECT COUNT(*) FROM "+tbl) if err := row.Scan(&v); err != nil { dbt.Fatal(err) } From 987e2b14d65e986562ad4473c903c74b246fc5ad Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:47:08 +0900 Subject: [PATCH 28/42] parallelize TestValuerWithValueReceiverGivenNilValue --- driver_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/driver_test.go b/driver_test.go index 8f8872446..b696402f2 100644 --- a/driver_test.go +++ b/driver_test.go @@ -3202,9 +3202,9 @@ func TestRowsColumnTypes(t *testing.T) { } func TestValuerWithValueReceiverGivenNilValue(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { - dbt.mustExec("CREATE TABLE test (value VARCHAR(255))") - dbt.db.Exec("INSERT INTO test VALUES (?)", (*testValuer)(nil)) + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { + dbt.mustExec("CREATE TABLE " + tbl + " (value VARCHAR(255))") + dbt.db.Exec("INSERT INTO "+tbl+" VALUES (?)", (*testValuer)(nil)) // This test will panic on the INSERT if ConvertValue() does not check for typed nil before calling Value() }) } From 91622f05d44481dd9867eeaaf382da239afe3925 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:48:18 +0900 Subject: [PATCH 29/42] parallelize TestRawBytesAreNotModified --- driver_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/driver_test.go b/driver_test.go index b696402f2..72f8a7f4e 100644 --- a/driver_test.go +++ b/driver_test.go @@ -3225,10 +3225,10 @@ func TestRawBytesAreNotModified(t *testing.T) { strings.Repeat(strings.ToUpper(blob), blobSize/len(blob)), } - runTests(t, dsn, func(dbt *DBTest) { - dbt.mustExec("CREATE TABLE test (id int, value BLOB) CHARACTER SET utf8") + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { + dbt.mustExec("CREATE TABLE " + tbl + " (id int, value BLOB) CHARACTER SET utf8") for i := 0; i < insertRows; i++ { - dbt.mustExec("INSERT INTO test VALUES (?, ?)", i+1, sqlBlobs[i&1]) + dbt.mustExec("INSERT INTO "+tbl+" VALUES (?, ?)", i+1, sqlBlobs[i&1]) } for i := 0; i < contextRaceIterations; i++ { @@ -3236,7 +3236,7 @@ func TestRawBytesAreNotModified(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - rows, err := dbt.db.QueryContext(ctx, `SELECT id, value FROM test`) + rows, err := dbt.db.QueryContext(ctx, `SELECT id, value FROM `+tbl) if err != nil { dbt.Fatal(err) } From fb42bbd2b47921f3ff4d45f9d65cea9ba79347c8 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:53:29 +0900 Subject: [PATCH 30/42] parallelize TestFoundRows --- driver_test.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/driver_test.go b/driver_test.go index 72f8a7f4e..c21903ffa 100644 --- a/driver_test.go +++ b/driver_test.go @@ -1404,12 +1404,12 @@ func TestLoadData(t *testing.T) { }) } -func TestFoundRows(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { - dbt.mustExec("CREATE TABLE test (id INT NOT NULL ,data INT NOT NULL)") - dbt.mustExec("INSERT INTO test (id, data) VALUES (0, 0),(0, 0),(1, 0),(1, 0),(1, 1)") +func TestFoundRows1(t *testing.T) { + runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { + dbt.mustExec("CREATE TABLE " + tbl + " (id INT NOT NULL ,data INT NOT NULL)") + dbt.mustExec("INSERT INTO " + tbl + " (id, data) VALUES (0, 0),(0, 0),(1, 0),(1, 0),(1, 1)") - res := dbt.mustExec("UPDATE test SET data = 1 WHERE id = 0") + res := dbt.mustExec("UPDATE " + tbl + " SET data = 1 WHERE id = 0") count, err := res.RowsAffected() if err != nil { dbt.Fatalf("res.RowsAffected() returned error: %s", err.Error()) @@ -1417,7 +1417,7 @@ func TestFoundRows(t *testing.T) { if count != 2 { dbt.Fatalf("Expected 2 affected rows, got %d", count) } - res = dbt.mustExec("UPDATE test SET data = 1 WHERE id = 1") + res = dbt.mustExec("UPDATE " + tbl + " SET data = 1 WHERE id = 1") count, err = res.RowsAffected() if err != nil { dbt.Fatalf("res.RowsAffected() returned error: %s", err.Error()) @@ -1426,11 +1426,14 @@ func TestFoundRows(t *testing.T) { dbt.Fatalf("Expected 2 affected rows, got %d", count) } }) - runTests(t, dsn+"&clientFoundRows=true", func(dbt *DBTest) { - dbt.mustExec("CREATE TABLE test (id INT NOT NULL ,data INT NOT NULL)") - dbt.mustExec("INSERT INTO test (id, data) VALUES (0, 0),(0, 0),(1, 0),(1, 0),(1, 1)") +} + +func TestFoundRows2(t *testing.T) { + runTestsParallel(t, dsn+"&clientFoundRows=true", func(dbt *DBTest, tbl string) { + dbt.mustExec("CREATE TABLE " + tbl + " (id INT NOT NULL ,data INT NOT NULL)") + dbt.mustExec("INSERT INTO " + tbl + " (id, data) VALUES (0, 0),(0, 0),(1, 0),(1, 0),(1, 1)") - res := dbt.mustExec("UPDATE test SET data = 1 WHERE id = 0") + res := dbt.mustExec("UPDATE " + tbl + " SET data = 1 WHERE id = 0") count, err := res.RowsAffected() if err != nil { dbt.Fatalf("res.RowsAffected() returned error: %s", err.Error()) @@ -1438,7 +1441,7 @@ func TestFoundRows(t *testing.T) { if count != 2 { dbt.Fatalf("Expected 2 matched rows, got %d", count) } - res = dbt.mustExec("UPDATE test SET data = 1 WHERE id = 1") + res = dbt.mustExec("UPDATE " + tbl + " SET data = 1 WHERE id = 1") count, err = res.RowsAffected() if err != nil { dbt.Fatalf("res.RowsAffected() returned error: %s", err.Error()) From 91b406521eb03d46ff82ca571422d33e71a9c5fc Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:55:02 +0900 Subject: [PATCH 31/42] parallelize TestRowsClose --- driver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver_test.go b/driver_test.go index c21903ffa..b318c4a04 100644 --- a/driver_test.go +++ b/driver_test.go @@ -1699,7 +1699,7 @@ func TestTimezoneConversion(t *testing.T) { // Special cases func TestRowsClose(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, _ string) { rows, err := dbt.db.Query("SELECT 1") if err != nil { dbt.Fatal(err) From d22420213664af602d4ca1751793a0b098ae57ae Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:55:25 +0900 Subject: [PATCH 32/42] parallelize TestCloseStmtBeforeRows --- driver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver_test.go b/driver_test.go index b318c4a04..2bf212165 100644 --- a/driver_test.go +++ b/driver_test.go @@ -1724,7 +1724,7 @@ func TestRowsClose(t *testing.T) { // dangling statements // http://code.google.com/p/go/issues/detail?id=3865 func TestCloseStmtBeforeRows(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, _ string) { stmt, err := dbt.db.Prepare("SELECT 1") if err != nil { dbt.Fatal(err) From 375bfee143ed98806f0909e7667c51e60c0ab2b7 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:56:24 +0900 Subject: [PATCH 33/42] parallelize TestStmtMultiRows --- driver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver_test.go b/driver_test.go index 2bf212165..b60b2f904 100644 --- a/driver_test.go +++ b/driver_test.go @@ -1765,7 +1765,7 @@ func TestCloseStmtBeforeRows(t *testing.T) { // It is valid to have multiple Rows for the same Stmt // http://code.google.com/p/go/issues/detail?id=3734 func TestStmtMultiRows(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, _ string) { stmt, err := dbt.db.Prepare("SELECT 1 UNION SELECT 0") if err != nil { dbt.Fatal(err) From 4022dd28cc4950069080fe97166172b1cd37ead7 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 00:57:19 +0900 Subject: [PATCH 34/42] Revert "parallelize TestRawBytesAreNotModified" This reverts commit 91622f05d44481dd9867eeaaf382da239afe3925. --- driver_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/driver_test.go b/driver_test.go index b60b2f904..2ab0a1245 100644 --- a/driver_test.go +++ b/driver_test.go @@ -3228,10 +3228,10 @@ func TestRawBytesAreNotModified(t *testing.T) { strings.Repeat(strings.ToUpper(blob), blobSize/len(blob)), } - runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) { - dbt.mustExec("CREATE TABLE " + tbl + " (id int, value BLOB) CHARACTER SET utf8") + runTests(t, dsn, func(dbt *DBTest) { + dbt.mustExec("CREATE TABLE test (id int, value BLOB) CHARACTER SET utf8") for i := 0; i < insertRows; i++ { - dbt.mustExec("INSERT INTO "+tbl+" VALUES (?, ?)", i+1, sqlBlobs[i&1]) + dbt.mustExec("INSERT INTO test VALUES (?, ?)", i+1, sqlBlobs[i&1]) } for i := 0; i < contextRaceIterations; i++ { @@ -3239,7 +3239,7 @@ func TestRawBytesAreNotModified(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - rows, err := dbt.db.QueryContext(ctx, `SELECT id, value FROM `+tbl) + rows, err := dbt.db.QueryContext(ctx, `SELECT id, value FROM test`) if err != nil { dbt.Fatal(err) } From dd2e1fbe283b85a16396da66955086361849805e Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 01:05:03 +0900 Subject: [PATCH 35/42] parallelize TestStaleConnectionChecks --- conncheck_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conncheck_test.go b/conncheck_test.go index f7e025680..6b60cb7d6 100644 --- a/conncheck_test.go +++ b/conncheck_test.go @@ -17,7 +17,7 @@ import ( ) func TestStaleConnectionChecks(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, _ string) { dbt.mustExec("SET @@SESSION.wait_timeout = 2") if err := dbt.db.Ping(); err != nil { From a65690437c3e5a500a76faaa7e6508aeb4db422a Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 01:08:39 +0900 Subject: [PATCH 36/42] parallelize TestFailingCharset --- driver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver_test.go b/driver_test.go index 2ab0a1245..abadcc757 100644 --- a/driver_test.go +++ b/driver_test.go @@ -1567,7 +1567,7 @@ func TestCharset(t *testing.T) { } func TestFailingCharset(t *testing.T) { - runTests(t, dsn+"&charset=none", func(dbt *DBTest) { + runTestsParallel(t, dsn+"&charset=none", func(dbt *DBTest, _ string) { // run query to really establish connection... _, err := dbt.db.Exec("SELECT 1") if err == nil { From b6c25908924cd27c219effe20b24f297f3d94a91 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 01:09:49 +0900 Subject: [PATCH 37/42] parallelize TestColumnsWithAlias --- driver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver_test.go b/driver_test.go index abadcc757..2f251e852 100644 --- a/driver_test.go +++ b/driver_test.go @@ -1616,7 +1616,7 @@ func TestCollation(t *testing.T) { } func TestColumnsWithAlias(t *testing.T) { - runTests(t, dsn+"&columnsWithAlias=true", func(dbt *DBTest) { + runTestsParallel(t, dsn+"&columnsWithAlias=true", func(dbt *DBTest, _ string) { rows := dbt.mustQuery("SELECT 1 AS A") defer rows.Close() cols, _ := rows.Columns() From 37fc7415cf0fe1a18660e330a2e9d944d4c104db Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 01:10:31 +0900 Subject: [PATCH 38/42] parallelize TestRawBytesResultExceedsBuffer --- driver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver_test.go b/driver_test.go index 2f251e852..7212e7a74 100644 --- a/driver_test.go +++ b/driver_test.go @@ -1640,7 +1640,7 @@ func TestColumnsWithAlias(t *testing.T) { } func TestRawBytesResultExceedsBuffer(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, _ string) { // defaultBufSize from buffer.go expected := strings.Repeat("abc", defaultBufSize) From b3df7bd130a21294a45c3733f1d2541b15582111 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 01:11:35 +0900 Subject: [PATCH 39/42] parallelize TestUnixSocketAuthFail --- driver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver_test.go b/driver_test.go index 7212e7a74..5b5f24a26 100644 --- a/driver_test.go +++ b/driver_test.go @@ -2101,7 +2101,7 @@ func TestInsertRetrieveEscapedData(t *testing.T) { } func TestUnixSocketAuthFail(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, _ string) { // Save the current logger so we can restore it. oldLogger := defaultLogger From ae497aee8abc58646763d2e70f96f47e501ae08f Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 01:12:57 +0900 Subject: [PATCH 40/42] parallelize TestSkipResults --- driver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver_test.go b/driver_test.go index 5b5f24a26..2bf0ccbee 100644 --- a/driver_test.go +++ b/driver_test.go @@ -2567,7 +2567,7 @@ func TestExecMultipleResults(t *testing.T) { // tests if rows are set in a proper state if some results were ignored before // calling rows.NextResultSet. func TestSkipResults(t *testing.T) { - runTests(t, dsn, func(dbt *DBTest) { + runTestsParallel(t, dsn, func(dbt *DBTest, _ string) { rows := dbt.mustQuery("SELECT 1, 2") defer rows.Close() From 8a466032f4a88b8091f4e91ba962b8061b8b7619 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 02:04:21 +0900 Subject: [PATCH 41/42] Add parallel flag to go test command --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8e1cb9bc3..aae421196 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -96,7 +96,7 @@ jobs: - name: test run: | - go test -v '-race' '-covermode=atomic' '-coverprofile=coverage.out' + go test -v '-race' '-covermode=atomic' '-coverprofile=coverage.out' -parallel 10 - name: Send coverage uses: shogo82148/actions-goveralls@v1 From 5965ccbf26d2f9359048cf9f687bfc6e33ada433 Mon Sep 17 00:00:00 2001 From: ICHINOSE Shogo Date: Wed, 13 Dec 2023 13:51:34 +0900 Subject: [PATCH 42/42] Revert "parallelize TestUnixSocketAuthFail" This reverts commit b3df7bd130a21294a45c3733f1d2541b15582111. --- driver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver_test.go b/driver_test.go index 2bf0ccbee..00fd3bbe0 100644 --- a/driver_test.go +++ b/driver_test.go @@ -2101,7 +2101,7 @@ func TestInsertRetrieveEscapedData(t *testing.T) { } func TestUnixSocketAuthFail(t *testing.T) { - runTestsParallel(t, dsn, func(dbt *DBTest, _ string) { + runTests(t, dsn, func(dbt *DBTest) { // Save the current logger so we can restore it. oldLogger := defaultLogger