MCPcopy
hub / github.com/grpc/grpc-go / New

Function New

internal/testutils/proxyserver/proxyserver.go:106–134  ·  view source on GitHub ↗

New initializes and starts a proxy server, registers a cleanup to stop it, and returns a ProxyServer.

(t *testing.T, reqCheck func(*http.Request), waitForServerHello bool)

Source from the content-addressed store, hash-verified

104// New initializes and starts a proxy server, registers a cleanup to
105// stop it, and returns a ProxyServer.
106func New(t *testing.T, reqCheck func(*http.Request), waitForServerHello bool) *ProxyServer {
107 t.Helper()
108 pLis, err := testutils.LocalTCPListener()
109 if err != nil {
110 t.Fatalf("failed to listen: %v", err)
111 }
112
113 p := &ProxyServer{
114 lis: pLis,
115 onRequest: reqCheck,
116 Addr: pLis.Addr().String(),
117 }
118
119 // Start the proxy server.
120 go func() {
121 for {
122 in, err := p.lis.Accept()
123 if err != nil {
124 return
125 }
126 // p.handleRequest is not invoked in a goroutine because the test
127 // proxy currently supports handling only one connection at a time.
128 p.handleRequest(t, in, waitForServerHello)
129 }
130 }()
131 t.Logf("Started proxy at: %q", pLis.Addr().String())
132 t.Cleanup(p.stop)
133 return p
134}

Calls 7

handleRequestMethod · 0.95
LocalTCPListenerFunction · 0.92
FatalfMethod · 0.65
StringMethod · 0.65
LogfMethod · 0.65
AddrMethod · 0.45
AcceptMethod · 0.45