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

Function setupTestServer

internal/xds/clients/grpctransport/grpc_transport_test.go:68–88  ·  view source on GitHub ↗

setupTestServer set up the gRPC server for AggregatedDiscoveryService. It creates an instance of testServer that returns the provided response from the StreamAggregatedResources() handler and registers it with a gRPC server.

(t *testing.T, response *v3discoverypb.DiscoveryResponse)

Source from the content-addressed store, hash-verified

66// creates an instance of testServer that returns the provided response from
67// the StreamAggregatedResources() handler and registers it with a gRPC server.
68func setupTestServer(t *testing.T, response *v3discoverypb.DiscoveryResponse) *testServer {
69 t.Helper()
70
71 lis, err := net.Listen("tcp", "localhost:0")
72 if err != nil {
73 t.Fatalf("Failed to listen on localhost:0: %v", err)
74 }
75 ts := &testServer{
76 requestChan: make(chan *v3discoverypb.DiscoveryRequest),
77 address: lis.Addr().String(),
78 response: response,
79 }
80
81 s := grpc.NewServer()
82
83 v3discoverygrpc.RegisterAggregatedDiscoveryServiceServer(s, ts)
84 go s.Serve(lis)
85 t.Cleanup(s.Stop)
86
87 return ts
88}
89
90// StreamAggregatedResources handles bidirectional streaming of
91// DiscoveryRequest and DiscoveryResponse. It waits for a message from the

Calls 5

ServeMethod · 0.95
NewServerFunction · 0.92
FatalfMethod · 0.65
StringMethod · 0.65
AddrMethod · 0.45

Tested by

no test coverage detected