| 662 | } |
| 663 | |
| 664 | func TestClientConnCount(t *testing.T) { |
| 665 | in := &proxy.Config{ |
| 666 | Addr: "127.0.0.1", |
| 667 | Port: 24015, |
| 668 | Instances: []proxy.InstanceConnConfig{ |
| 669 | {Name: "proj:region:pg"}, |
| 670 | }, |
| 671 | MaxConnections: 10, |
| 672 | } |
| 673 | |
| 674 | c, err := proxy.NewClient(context.Background(), &fakeDialer{}, testLogger, in, nil) |
| 675 | if err != nil { |
| 676 | t.Fatalf("proxy.NewClient error: %v", err) |
| 677 | } |
| 678 | defer c.Close() |
| 679 | go c.Serve(context.Background(), func() {}) |
| 680 | |
| 681 | gotOpen, gotMax := c.ConnCount() |
| 682 | if gotOpen != 0 { |
| 683 | t.Fatalf("want 0 open connections, got = %v", gotOpen) |
| 684 | } |
| 685 | if gotMax != 10 { |
| 686 | t.Fatalf("want 10 max connections, got = %v", gotMax) |
| 687 | } |
| 688 | |
| 689 | conn := tryTCPDial(t, "127.0.0.1:24015") |
| 690 | defer conn.Close() |
| 691 | |
| 692 | verifyOpen := func(t *testing.T, want uint64) { |
| 693 | var got uint64 |
| 694 | for i := 0; i < 10; i++ { |
| 695 | got, _ = c.ConnCount() |
| 696 | if got == want { |
| 697 | return |
| 698 | } |
| 699 | time.Sleep(100 * time.Millisecond) |
| 700 | } |
| 701 | t.Fatalf("open connections, want = %v, got = %v", want, got) |
| 702 | } |
| 703 | verifyOpen(t, 1) |
| 704 | } |
| 705 | |
| 706 | func TestSQLDataWarmup(t *testing.T) { |
| 707 | tcs := []struct { |