(t *testing.T, copts ConnectOptions, connCh chan net.Conn)
| 646 | } |
| 647 | |
| 648 | func setUpControllablePingServer(t *testing.T, copts ConnectOptions, connCh chan net.Conn) (*controllablePingServer, *http2Client, func()) { |
| 649 | lis, err := net.Listen("tcp", "localhost:0") |
| 650 | if err != nil { |
| 651 | t.Fatalf("Failed to listen: %v", err) |
| 652 | } |
| 653 | s := &controllablePingServer{} |
| 654 | s.setPingAck(true) |
| 655 | // Launch a server. |
| 656 | go func() { |
| 657 | defer lis.Close() |
| 658 | conn, err := lis.Accept() |
| 659 | if err != nil { |
| 660 | t.Errorf("Error at server-side while accepting: %v", err) |
| 661 | close(connCh) |
| 662 | return |
| 663 | } |
| 664 | framer := http2.NewFramer(conn, conn) |
| 665 | if err := framer.WriteSettings(); err != nil { |
| 666 | t.Errorf("Error at server-side while writing settings: %v", err) |
| 667 | close(connCh) |
| 668 | return |
| 669 | } |
| 670 | connCh <- conn |
| 671 | s.serve(t, conn) |
| 672 | }() |
| 673 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 674 | t.Cleanup(cancel) |
| 675 | connectCtx, cCancel := context.WithTimeout(context.Background(), 2*time.Second) |
| 676 | tr, err := NewHTTP2Client(connectCtx, ctx, resolver.Address{Addr: lis.Addr().String()}, copts, func(GoAwayInfo) {}) |
| 677 | if err != nil { |
| 678 | cCancel() // Do not cancel in success path. |
| 679 | // Server clean-up. |
| 680 | lis.Close() |
| 681 | if conn, ok := <-connCh; ok { |
| 682 | conn.Close() |
| 683 | } |
| 684 | t.Fatalf("Failed to dial: %v", err) |
| 685 | } |
| 686 | return s, tr.(*http2Client), cCancel |
| 687 | } |
| 688 | |
| 689 | // TestInflightStreamClosing ensures that closing in-flight stream |
| 690 | // sends status error to concurrent stream reader. |
no test coverage detected