TestUpdateAddresses_NoopIfCalledWithSameAddresses tests that UpdateAddresses should be noop if UpdateAddresses is called with the same list of addresses, even when the SubConn is in Connecting and doesn't have a current address.
(t *testing.T)
| 668 | // should be noop if UpdateAddresses is called with the same list of addresses, |
| 669 | // even when the SubConn is in Connecting and doesn't have a current address. |
| 670 | func (s) TestUpdateAddresses_NoopIfCalledWithSameAddresses(t *testing.T) { |
| 671 | lis1, err := net.Listen("tcp", "localhost:0") |
| 672 | if err != nil { |
| 673 | t.Fatalf("Error while listening. Err: %v", err) |
| 674 | } |
| 675 | defer lis1.Close() |
| 676 | |
| 677 | lis2, err := net.Listen("tcp", "localhost:0") |
| 678 | if err != nil { |
| 679 | t.Fatalf("Error while listening. Err: %v", err) |
| 680 | } |
| 681 | defer lis2.Close() |
| 682 | |
| 683 | lis3, err := net.Listen("tcp", "localhost:0") |
| 684 | if err != nil { |
| 685 | t.Fatalf("Error while listening. Err: %v", err) |
| 686 | } |
| 687 | defer lis3.Close() |
| 688 | |
| 689 | closeServer2 := make(chan struct{}) |
| 690 | exitCh := make(chan struct{}) |
| 691 | server1ContactedFirstTime := make(chan struct{}) |
| 692 | server1ContactedSecondTime := make(chan struct{}) |
| 693 | server2ContactedFirstTime := make(chan struct{}) |
| 694 | server2ContactedSecondTime := make(chan struct{}) |
| 695 | server3Contacted := make(chan struct{}) |
| 696 | |
| 697 | defer close(exitCh) |
| 698 | |
| 699 | // Launch server 1. |
| 700 | go func() { |
| 701 | // First, let's allow the initial connection to go READY. We need to do |
| 702 | // this because tryUpdateAddrs only works after there's some non-nil |
| 703 | // address on the ac, and curAddress is only set after READY. |
| 704 | conn1, err := lis1.Accept() |
| 705 | if err != nil { |
| 706 | t.Error(err) |
| 707 | return |
| 708 | } |
| 709 | go keepReading(conn1) |
| 710 | |
| 711 | framer := http2.NewFramer(conn1, conn1) |
| 712 | if err := framer.WriteSettings(http2.Setting{}); err != nil { |
| 713 | t.Errorf("Error while writing settings frame. %v", err) |
| 714 | return |
| 715 | } |
| 716 | |
| 717 | // nextStateNotifier() is updated after balancerBuilder.Build(), which |
| 718 | // is called by ClientConn.Connect in stayConnected. It's safe to do it |
| 719 | // here because lis1.Accept blocks until ClientConn.Connect is called |
| 720 | // and the balancer is built to process the addresses. |
| 721 | stateNotifications := testBalancerBuilder.nextStateNotifier() |
| 722 | // Wait for the transport to become ready. |
| 723 | for { |
| 724 | select { |
| 725 | case st := <-stateNotifications: |
| 726 | if st == connectivity.Ready { |
| 727 | goto ready |
nothing calls this directly
no test coverage detected