MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/cloud-sql-proxy / TestRunConnectionCheck

Function TestRunConnectionCheck

internal/proxy/proxy_test.go:815–859  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

813}
814
815func TestRunConnectionCheck(t *testing.T) {
816 in := &proxy.Config{
817 Addr: "127.0.0.1",
818 Port: 24017,
819 Instances: []proxy.InstanceConnConfig{
820 {Name: "proj:region:pg"},
821 },
822 RunConnectionTest: true,
823 }
824 d := &fakeDialer{}
825 c, err := proxy.NewClient(context.Background(), d, testLogger, in, nil)
826 if err != nil {
827 t.Fatalf("proxy.NewClient error: %v", err)
828 }
829 defer func(c *proxy.Client) {
830 err := c.Close()
831 if err != nil {
832 t.Log(err)
833 }
834 }(c)
835 go func() {
836 // Serve alone without any connections will still verify that the
837 // provided instances are reachable.
838 _ = c.Serve(context.Background(), func() {})
839 }()
840
841 verifyDialAttempts := func() error {
842 var tries int
843 for {
844 tries++
845 if tries == 10 {
846 return errors.New("failed to verify dial tries after 10 tries")
847 }
848 if got := d.dialAttempts(); got > 0 {
849 return nil
850 }
851 time.Sleep(100 * time.Millisecond)
852 }
853 }
854
855 if err := verifyDialAttempts(); err != nil {
856 t.Fatal(err)
857 }
858
859}
860
861func TestProxyInitializationWithFailedUnixSocket(t *testing.T) {
862 ctx := context.Background()

Callers

nothing calls this directly

Calls 4

CloseMethod · 0.95
ServeMethod · 0.95
dialAttemptsMethod · 0.95
NewClientFunction · 0.92

Tested by

no test coverage detected