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

Function TestSQLDataWarmup

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

Source from the content-addressed store, hash-verified

704}
705
706func TestSQLDataWarmup(t *testing.T) {
707 tcs := []struct {
708 desc string
709 in *proxy.Config
710 want int
711 }{
712 {
713 desc: "standard warmup",
714 in: &proxy.Config{
715 Instances: []proxy.InstanceConnConfig{{Name: "proj:reg:inst", Port: 30104}},
716 },
717 want: 1,
718 },
719 {
720 desc: "warmup skipped globally",
721 in: &proxy.Config{
722 SQLDataEnabled: true,
723 Instances: []proxy.InstanceConnConfig{{Name: "proj:reg:inst", Port: 30105}},
724 },
725 want: 0,
726 },
727 {
728 desc: "warmup skipped per-instance",
729 in: &proxy.Config{
730 Instances: []proxy.InstanceConnConfig{{
731 Name: "proj:reg:inst",
732 Port: 30106,
733 SQLDataEnabled: pointer(true),
734 }},
735 },
736 want: 0,
737 },
738 }
739
740 for _, tc := range tcs {
741 t.Run(tc.desc, func(t *testing.T) {
742 d := &fakeDialer{}
743 c, err := proxy.NewClient(context.Background(), d, testLogger, tc.in, nil)
744 if err != nil {
745 t.Fatalf("proxy.NewClient error: %v", err)
746 }
747 defer c.Close()
748
749 var got int
750 for i := 0; i < 10; i++ {
751 got = d.engineVersionAttempts()
752 if got == tc.want {
753 return
754 }
755 time.Sleep(100 * time.Millisecond)
756 }
757 t.Fatalf("warmup attempts, want = %v, got = %v", tc.want, got)
758 })
759 }
760}
761
762func TestCheckConnections(t *testing.T) {
763 in := &proxy.Config{

Callers

nothing calls this directly

Calls 4

CloseMethod · 0.95
engineVersionAttemptsMethod · 0.95
NewClientFunction · 0.92
pointerFunction · 0.70

Tested by

no test coverage detected