MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / startTestServer

Function startTestServer

internal/bridge/mockserver_test.go:286–324  ·  view source on GitHub ↗

--------------------------------------------------------------------------- startTestServer spins up an in-memory gRPC server with bufconn and returns the mock server, a client, and a cleanup function. ---------------------------------------------------------------------------

(t *testing.T)

Source from the content-addressed store, hash-verified

284// ---------------------------------------------------------------------------
285
286func startTestServer(t *testing.T) (*testServer, listenerrpc.ListenerRPCClient, func()) {
287 t.Helper()
288
289 srv := newTestServer()
290 lis := bufconn.Listen(bufSize)
291
292 gs := grpc.NewServer()
293 listenerrpc.RegisterListenerRPCServer(gs, srv)
294
295 go func() {
296 if err := gs.Serve(lis); err != nil {
297 // Ignore errors after cleanup.
298 }
299 }()
300
301 dialer := func(ctx context.Context, _ string) (net.Conn, error) {
302 return lis.DialContext(ctx)
303 }
304
305 conn, err := grpc.DialContext(
306 context.Background(),
307 "bufnet",
308 grpc.WithContextDialer(dialer),
309 grpc.WithTransportCredentials(insecure.NewCredentials()),
310 )
311 if err != nil {
312 t.Fatalf("failed to dial bufconn: %v", err)
313 }
314
315 client := listenerrpc.NewListenerRPCClient(conn)
316
317 cleanup := func() {
318 conn.Close()
319 gs.Stop()
320 lis.Close()
321 }
322
323 return srv, client, cleanup
324}
325
326// ---------------------------------------------------------------------------
327// newTestBridgeWithRPC creates a Bridge connected to a real gRPC client,

Calls 3

StopMethod · 0.95
newTestServerFunction · 0.70
CloseMethod · 0.65

Tested by

no test coverage detected