MCPcopy
hub / github.com/go-sql-driver/mysql / runTestsParallel

Function runTestsParallel

driver_test.go:206–260  ·  view source on GitHub ↗

runTestsParallel runs the tests in parallel with a separate database connection for each test.

(t *testing.T, dsn string, tests ...func(dbt *DBTest, tableName string))

Source from the content-addressed store, hash-verified

204
205// runTestsParallel runs the tests in parallel with a separate database connection for each test.
206func runTestsParallel(t *testing.T, dsn string, tests ...func(dbt *DBTest, tableName string)) {
207 if !available {
208 t.Skipf("MySQL server not running on %s", netAddr)
209 }
210
211 newTableName := func(t *testing.T) string {
212 t.Helper()
213 var buf [8]byte
214 if _, err := rand.Read(buf[:]); err != nil {
215 t.Fatal(err)
216 }
217 return fmt.Sprintf("test_%x", buf[:])
218 }
219
220 t.Parallel()
221 for _, test := range tests {
222
223 t.Run("default", func(t *testing.T) {
224 t.Parallel()
225
226 tableName := newTableName(t)
227 db, err := sql.Open("mysql", dsn)
228 if err != nil {
229 t.Fatalf("error connecting: %s", err.Error())
230 }
231 t.Cleanup(func() {
232 db.Exec("DROP TABLE IF EXISTS " + tableName)
233 db.Close()
234 })
235
236 dbt := &DBTest{t, db}
237 test(dbt, tableName)
238 })
239
240 dsn2 := dsn + "&interpolateParams=true"
241 if _, err := ParseDSN(dsn2); err == errInvalidDSNUnsafeCollation {
242 t.Run("interpolateParams", func(t *testing.T) {
243 t.Parallel()
244
245 tableName := newTableName(t)
246 db, err := sql.Open("mysql", dsn2)
247 if err != nil {
248 t.Fatalf("error connecting: %s", err.Error())
249 }
250 t.Cleanup(func() {
251 db.Exec("DROP TABLE IF EXISTS " + tableName)
252 db.Close()
253 })
254
255 dbt := &DBTest{t, db}
256 test(dbt, tableName)
257 })
258 }
259 }
260}
261
262func (dbt *DBTest) fail(method, query string, err error) {
263 dbt.Helper()

Callers 15

TestEmptyQueryFunction · 0.85
TestCRUDFunction · 0.85
TestNumbersToAnyFunction · 0.85
TestIntFunction · 0.85
TestFloat32Function · 0.85
TestFloat64Function · 0.85
TestFloat64PlaceholderFunction · 0.85
TestStringFunction · 0.85
TestRawBytesFunction · 0.85
TestRawMessageFunction · 0.85
TestValuerFunction · 0.85

Calls 6

ParseDSNFunction · 0.85
OpenMethod · 0.80
ReadMethod · 0.45
ErrorMethod · 0.45
ExecMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…