makeHangDialer returns a dialer that notifies the returned channel when a connection is dialed and then hangs until the test finishes.
(tb testing.TB)
| 708 | // makeHangDialer returns a dialer that notifies the returned channel when a |
| 709 | // connection is dialed and then hangs until the test finishes. |
| 710 | func makeHangDialer(tb testing.TB) (netx.DialFunc, chan struct{}) { |
| 711 | done := make(chan struct{}) |
| 712 | tb.Cleanup(func() { |
| 713 | close(done) |
| 714 | }) |
| 715 | |
| 716 | gotConn := make(chan struct{}, 1) |
| 717 | fn := func(ctx context.Context, network, address string) (net.Conn, error) { |
| 718 | // Signal that we have a new connection |
| 719 | tb.Logf("hangDialer: called with network=%q address=%q", network, address) |
| 720 | select { |
| 721 | case gotConn <- struct{}{}: |
| 722 | default: |
| 723 | } |
| 724 | |
| 725 | // Hang until the test is done. |
| 726 | select { |
| 727 | case <-ctx.Done(): |
| 728 | tb.Logf("context done") |
| 729 | case <-done: |
| 730 | tb.Logf("function completed") |
| 731 | } |
| 732 | return nil, fmt.Errorf("canceled") |
| 733 | } |
| 734 | return fn, gotConn |
| 735 | } |
| 736 | |
| 737 | // TestTCPForwardLimits verifies that the limits on the TCP forwarder work in a |
| 738 | // success case (i.e. when we don't hit the limit). |
no test coverage detected
searching dependent graphs…