-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
introduce runTestsParallel #1489
Conversation
This reverts commit d3ed0b2.
t.Run("default", func(t *testing.T) { | ||
dbt := &DBTest{t, db} | ||
t.Cleanup(func() { | ||
dbt.db.Exec("DROP TABLE IF EXISTS test") | ||
}) | ||
test(dbt) | ||
dbt.db.Exec("DROP TABLE IF EXISTS test") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now redundant with the Cleanup.
if _, err := rand.Read(buf[:]); err != nil { | ||
t.Fatal(err) | ||
} | ||
tableName := fmt.Sprintf("test_%x", buf[:]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a non-zero risk of having two tests started with the same table name.
It would be better to use the index of the iteration of the for
loop and a hash of the test name from which runTestsParallel is called.
db.Exec("DROP TABLE IF EXISTS " + tableName) | ||
dbt := &DBTest{t, db} | ||
test(dbt, tableName) | ||
dbt.db.Exec("DROP TABLE IF EXISTS test") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining reference to table test
.
db.Exec("DROP TABLE IF EXISTS " + tableName) | ||
dbt := &DBTest{t, db} | ||
test(dbt, tableName) | ||
dbt.db.Exec("DROP TABLE IF EXISTS test") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining reference to table test
.
The two functions below could be useful to abstract the handling of the DB connection life cycle in a test: func openDB(tb testing.TB, dsn string) *sql.DB {
tb.Helper()
db, err := sql.Open("mysql", dsn)
if err != nil {
tb.Fatalf("open %q: %v", path, err)
}
tb.Cleanup(func() {
err := db.Close()
if err != nil {
tb.Error("close DB:", err)
}
})
return db
}
func openDBTest(t *testing.T, dsn string) *DBTest {
tb.Helper()
db := openDB(dsn)
return &DBTest{t, db}
} They could be used in both |
Could not speed up as much as I expected. Close it. |
Description
Please explain the changes you made here.
Checklist