MCPcopy Create free account
hub / github.com/cortexproject/cortex / testFrontend

Function testFrontend

pkg/frontend/v1/frontend_test.go:230–295  ·  view source on GitHub ↗
(t *testing.T, config Config, handler http.Handler, test func(addr string, frontend *Frontend), matchMaxConcurrency bool, l log.Logger, reg prometheus.Registerer)

Source from the content-addressed store, hash-verified

228}
229
230func testFrontend(t *testing.T, config Config, handler http.Handler, test func(addr string, frontend *Frontend), matchMaxConcurrency bool, l log.Logger, reg prometheus.Registerer) {
231 logger := log.NewNopLogger()
232 if l != nil {
233 logger = l
234 }
235
236 var workerConfig querier_worker.Config
237 flagext.DefaultValues(&workerConfig)
238 workerConfig.Parallelism = 1
239 workerConfig.MatchMaxConcurrency = matchMaxConcurrency
240 workerConfig.MaxConcurrentRequests = 1
241
242 // localhost:0 prevents firewall warnings on Mac OS X.
243 grpcListen, err := net.Listen("tcp", "localhost:0")
244 require.NoError(t, err)
245 workerConfig.FrontendAddress = grpcListen.Addr().String()
246
247 httpListen, err := net.Listen("tcp", "localhost:0")
248 require.NoError(t, err)
249
250 limits := MockLimits{MockLimits: queue.MockLimits{MaxOutstanding: 100}}
251 v1, err := New(config, limits, logger, reg, transport.NewRetry(0, nil))
252 require.NoError(t, err)
253 require.NotNil(t, v1)
254 require.NoError(t, services.StartAndAwaitRunning(context.Background(), v1))
255 defer func() {
256 require.NoError(t, services.StopAndAwaitTerminated(context.Background(), v1))
257 }()
258
259 grpcServer := grpc.NewServer(
260 grpc.StreamInterceptor(otgrpc.OpenTracingStreamServerInterceptor(opentracing.GlobalTracer())),
261 )
262 defer grpcServer.GracefulStop()
263
264 frontendv1pb.RegisterFrontendServer(grpcServer, v1)
265
266 // Default HTTP handler config.
267 handlerCfg := transport.HandlerConfig{}
268 tenantFederationCfg := tenantfederation.Config{}
269
270 flagext.DefaultValues(&handlerCfg)
271
272 rt := transport.AdaptGrpcRoundTripperToHTTPRoundTripper(v1)
273 r := mux.NewRouter()
274 r.PathPrefix("/").Handler(middleware.Merge(
275 middleware.AuthenticateUser,
276 middleware.Tracer{},
277 ).Wrap(transport.NewHandler(handlerCfg, tenantFederationCfg, rt, logger, nil)))
278
279 httpServer := http.Server{
280 Handler: r,
281 }
282 defer httpServer.Shutdown(context.Background()) //nolint:errcheck
283
284 go httpServer.Serve(httpListen) //nolint:errcheck
285 go grpcServer.Serve(grpcListen) //nolint:errcheck
286
287 var worker services.Service

Callers 4

TestFrontendFunction · 0.70
TestFrontendCancelFunction · 0.70

Calls 12

DefaultValuesFunction · 0.92
NewRetryFunction · 0.92
StartAndAwaitRunningFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
RegisterFrontendServerFunction · 0.92
NewHandlerFunction · 0.92
ShutdownMethod · 0.80
NewFunction · 0.70
StringMethod · 0.65
WrapMethod · 0.65
MergeMethod · 0.65

Tested by

no test coverage detected