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

Function TestConnectWithFallback

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

Source from the content-addressed store, hash-verified

671}
672
673func TestConnectWithFallback(t *testing.T) {
674 t.Parallel()
675
676 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
677 defer cancel()
678
679 config, err := pgconn.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
680 require.NoError(t, err)
681
682 // Prepend current primary config to fallbacks
683 config.Fallbacks = append([]*pgconn.FallbackConfig{
684 {
685 Host: config.Host,
686 Port: config.Port,
687 TLSConfig: config.TLSConfig,
688 },
689 }, config.Fallbacks...)
690
691 // Make primary config bad
692 config.Host = "localhost"
693 config.Port = 1 // presumably nothing listening here
694
695 // Prepend bad first fallback
696 config.Fallbacks = append([]*pgconn.FallbackConfig{
697 {
698 Host: "localhost",
699 Port: 1,
700 TLSConfig: config.TLSConfig,
701 },
702 }, config.Fallbacks...)
703
704 conn, err := pgconn.ConnectConfig(ctx, config)
705 require.NoError(t, err)
706 closeConn(t, conn)
707}
708
709func TestConnectFailsWithResolveFailureAndFailedConnectionAttempts(t *testing.T) {
710 t.Parallel()

Callers

nothing calls this directly

Calls 3

ParseConfigFunction · 0.92
ConnectConfigFunction · 0.92
closeConnFunction · 0.70

Tested by

no test coverage detected