| 120 | } |
| 121 | |
| 122 | func startBackends(t *testing.T, numBackends int) []*stubserver.StubServer { |
| 123 | backends := make([]*stubserver.StubServer, 0, numBackends) |
| 124 | // Construct and start working backends. |
| 125 | for i := 0; i < numBackends; i++ { |
| 126 | backend := &stubserver.StubServer{ |
| 127 | EmptyCallF: func(context.Context, *testpb.Empty) (*testpb.Empty, error) { |
| 128 | return &testpb.Empty{}, nil |
| 129 | }, |
| 130 | FullDuplexCallF: func(stream testgrpc.TestService_FullDuplexCallServer) error { |
| 131 | <-stream.Context().Done() |
| 132 | return nil |
| 133 | }, |
| 134 | } |
| 135 | if err := backend.StartServer(); err != nil { |
| 136 | t.Fatalf("Failed to start backend: %v", err) |
| 137 | } |
| 138 | t.Logf("Started good TestService backend at: %q", backend.Address) |
| 139 | t.Cleanup(func() { backend.Stop() }) |
| 140 | backends = append(backends, backend) |
| 141 | } |
| 142 | return backends |
| 143 | } |
| 144 | |
| 145 | // setupBackends spins up three test backends, each listening on a port on |
| 146 | // localhost. The three backends always reply with an empty response with no |