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

Function TestConnectorObeysDialTimeouts

driver_test.go:3334–3359  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3332type dialCtxKey struct{}
3333
3334func 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
3361func configForTests(t *testing.T) *Config {
3362 if !available {

Callers

nothing calls this directly

Calls 6

RegisterDialContextFunction · 0.85
OpenMethod · 0.80
ValueMethod · 0.45
ErrorMethod · 0.45
CloseMethod · 0.45
ExecContextMethod · 0.45

Tested by

no test coverage detected