(t *testing.T)
| 3409 | } |
| 3410 | |
| 3411 | func TestConnectorTimeoutsDuringOpen(t *testing.T) { |
| 3412 | RegisterDialContext("slowconn", func(ctx context.Context, addr string) (net.Conn, error) { |
| 3413 | var d net.Dialer |
| 3414 | conn, err := d.DialContext(ctx, prot, addr) |
| 3415 | if err != nil { |
| 3416 | return nil, err |
| 3417 | } |
| 3418 | return &slowConnection{Conn: conn, slowdown: 100 * time.Millisecond}, nil |
| 3419 | }) |
| 3420 | |
| 3421 | mycnf := configForTests(t) |
| 3422 | mycnf.Net = "slowconn" |
| 3423 | |
| 3424 | conn, err := NewConnector(mycnf) |
| 3425 | if err != nil { |
| 3426 | t.Fatal(err) |
| 3427 | } |
| 3428 | |
| 3429 | hijack := &connectorHijack{Connector: conn} |
| 3430 | |
| 3431 | db := sql.OpenDB(hijack) |
| 3432 | defer db.Close() |
| 3433 | |
| 3434 | ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond) |
| 3435 | defer cancel() |
| 3436 | |
| 3437 | _, err = db.ExecContext(ctx, "DO 1") |
| 3438 | if err != context.DeadlineExceeded { |
| 3439 | t.Fatalf("ExecContext should have timed out") |
| 3440 | } |
| 3441 | if hijack.connErr != context.DeadlineExceeded { |
| 3442 | t.Fatalf("(*Connector).Connect should have timed out") |
| 3443 | } |
| 3444 | } |
| 3445 | |
| 3446 | // A connection which can only be closed. |
| 3447 | type dummyConnection struct { |
nothing calls this directly
no test coverage detected