MCPcopy
hub / github.com/jackc/pgx / TestConnectTimeoutStuckOnTLSHandshake

Function TestConnectTimeoutStuckOnTLSHandshake

pgconn/pgconn_test.go:447–519  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

445}
446
447func TestConnectTimeoutStuckOnTLSHandshake(t *testing.T) {
448 t.Parallel()
449 tests := []struct {
450 name string
451 connect func(connStr string) error
452 }{
453 {
454 name: "via context that times out",
455 connect: func(connStr string) error {
456 ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*10)
457 defer cancel()
458 _, err := pgconn.Connect(ctx, connStr)
459 return err
460 },
461 },
462 {
463 name: "via config ConnectTimeout",
464 connect: func(connStr string) error {
465 conf, err := pgconn.ParseConfig(connStr)
466 require.NoError(t, err)
467 conf.ConnectTimeout = time.Millisecond * 10
468 _, err = pgconn.ConnectConfig(context.Background(), conf)
469 return err
470 },
471 },
472 }
473 for _, tt := range tests {
474 t.Run(tt.name, func(t *testing.T) {
475 t.Parallel()
476 ln, err := net.Listen("tcp", "127.0.0.1:")
477 require.NoError(t, err)
478 defer ln.Close()
479
480 serverErrChan := make(chan error, 1)
481 go func() {
482 conn, err := ln.Accept()
483 if err != nil {
484 serverErrChan <- err
485 return
486 }
487 defer conn.Close()
488
489 var buf []byte
490 _, err = conn.Read(buf)
491 if err != nil {
492 serverErrChan <- err
493 return
494 }
495
496 // Sleeping to hang the TLS handshake.
497 time.Sleep(time.Minute)
498 }()
499
500 host, port, _ := strings.Cut(ln.Addr().String(), ":")
501 connStr := fmt.Sprintf("host=%s port=%s", host, port)
502
503 errChan := make(chan error)
504 go func() {

Callers

nothing calls this directly

Calls 8

ConnectFunction · 0.92
ParseConfigFunction · 0.92
ConnectConfigFunction · 0.92
TimeoutFunction · 0.92
CloseMethod · 0.65
RunMethod · 0.45
ReadMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected