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

Function startBackend

balancer/rls/helpers_test.go:169–188  ·  view source on GitHub ↗

startBackend starts a backend implementing the TestService on a local port. It returns a channel for tests to get notified whenever an RPC is invoked on the backend. This allows tests to ensure that RPCs reach expected backends. Also returns the address of the backend.

(t *testing.T, sopts ...grpc.ServerOption)

Source from the content-addressed store, hash-verified

167// the backend. This allows tests to ensure that RPCs reach expected backends.
168// Also returns the address of the backend.
169func startBackend(t *testing.T, sopts ...grpc.ServerOption) (rpcCh chan struct{}, address string) {
170 t.Helper()
171
172 rpcCh = make(chan struct{}, 1)
173 backend := &stubserver.StubServer{
174 EmptyCallF: func(context.Context, *testpb.Empty) (*testpb.Empty, error) {
175 select {
176 case rpcCh <- struct{}{}:
177 default:
178 }
179 return &testpb.Empty{}, nil
180 },
181 }
182 if err := backend.StartServer(sopts...); err != nil {
183 t.Fatalf("Failed to start backend: %v", err)
184 }
185 t.Logf("Started TestService backend at: %q", backend.Address)
186 t.Cleanup(func() { backend.Stop() })
187 return rpcCh, backend.Address
188}
189
190// startManualResolverWithConfig registers and returns a manual resolver which
191// pushes the RLS LB policy's service config on the channel.

Calls 4

StartServerMethod · 0.95
StopMethod · 0.95
FatalfMethod · 0.65
LogfMethod · 0.65

Tested by

no test coverage detected