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

Function TestConnectorTimeoutsWatchCancel

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

Source from the content-addressed store, hash-verified

3455}
3456
3457func TestConnectorTimeoutsWatchCancel(t *testing.T) {
3458 var (
3459 cancel func() // Used to cancel the context just after connecting.
3460 created *dummyConnection // The created connection.
3461 )
3462
3463 RegisterDialContext("TestConnectorTimeoutsWatchCancel", func(ctx context.Context, addr string) (net.Conn, error) {
3464 // Canceling at this time triggers the watchCancel error branch in Connect().
3465 cancel()
3466 created = &dummyConnection{}
3467 return created, nil
3468 })
3469
3470 mycnf := NewConfig()
3471 mycnf.User = "root"
3472 mycnf.Addr = "foo"
3473 mycnf.Net = "TestConnectorTimeoutsWatchCancel"
3474
3475 conn, err := NewConnector(mycnf)
3476 if err != nil {
3477 t.Fatal(err)
3478 }
3479
3480 db := sql.OpenDB(conn)
3481 defer db.Close()
3482
3483 var ctx context.Context
3484 ctx, cancel = context.WithCancel(context.Background())
3485 defer cancel()
3486
3487 if _, err := db.Conn(ctx); err != context.Canceled {
3488 t.Errorf("got %v, want context.Canceled", err)
3489 }
3490
3491 if created == nil {
3492 t.Fatal("no connection created")
3493 }
3494 if !created.closed {
3495 t.Errorf("connection not closed")
3496 }
3497}
3498
3499func TestConnectionAttributes(t *testing.T) {
3500 if !available {

Callers

nothing calls this directly

Calls 4

RegisterDialContextFunction · 0.85
NewConfigFunction · 0.85
NewConnectorFunction · 0.85
CloseMethod · 0.45

Tested by

no test coverage detected