(t *testing.T)
| 3332 | type dialCtxKey struct{} |
| 3333 | |
| 3334 | func TestConnectorObeysDialTimeouts(t *testing.T) { |
| 3335 | if !available { |
| 3336 | t.Skipf("MySQL server not running on %s", netAddr) |
| 3337 | } |
| 3338 | |
| 3339 | RegisterDialContext("dialctxtest", func(ctx context.Context, addr string) (net.Conn, error) { |
| 3340 | var d net.Dialer |
| 3341 | if !ctx.Value(dialCtxKey{}).(bool) { |
| 3342 | return nil, fmt.Errorf("test error: query context is not propagated to our dialer") |
| 3343 | } |
| 3344 | return d.DialContext(ctx, prot, addr) |
| 3345 | }) |
| 3346 | |
| 3347 | db, err := sql.Open(driverNameTest, fmt.Sprintf("%s:%s@dialctxtest(%s)/%s?timeout=30s", user, pass, addr, dbname)) |
| 3348 | if err != nil { |
| 3349 | t.Fatalf("error connecting: %s", err.Error()) |
| 3350 | } |
| 3351 | defer db.Close() |
| 3352 | |
| 3353 | ctx := context.WithValue(context.Background(), dialCtxKey{}, true) |
| 3354 | |
| 3355 | _, err = db.ExecContext(ctx, "DO 1") |
| 3356 | if err != nil { |
| 3357 | t.Fatal(err) |
| 3358 | } |
| 3359 | } |
| 3360 | |
| 3361 | func configForTests(t *testing.T) *Config { |
| 3362 | if !available { |
nothing calls this directly
no test coverage detected