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)
| 167 | // the backend. This allows tests to ensure that RPCs reach expected backends. |
| 168 | // Also returns the address of the backend. |
| 169 | func 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. |
no test coverage detected