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

Function TestConnectorTimeoutsDuringOpen

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

Source from the content-addressed store, hash-verified

3409}
3410
3411func 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.
3447type dummyConnection struct {

Callers

nothing calls this directly

Calls 5

RegisterDialContextFunction · 0.85
configForTestsFunction · 0.85
NewConnectorFunction · 0.85
CloseMethod · 0.45
ExecContextMethod · 0.45

Tested by

no test coverage detected