MCPcopy
hub / github.com/grafana/dskit / TestRunReturnsError

Function TestRunReturnsError

server/server_test.go:488–544  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

486}
487
488func TestRunReturnsError(t *testing.T) {
489 testCases := []struct {
490 protocol string
491 }{
492 {
493 protocol: "http",
494 },
495 {
496 protocol: "grpc",
497 },
498 }
499 for _, tc := range testCases {
500 for _, network := range []string{"default", "tcpV4"} {
501 t.Run(network, func(t *testing.T) {
502 var level log.Level
503 require.NoError(t, level.Set("info"))
504 cfg := Config{
505 Registerer: prometheus.NewPedanticRegistry(),
506 LogLevel: level,
507 MetricsNamespace: fmt.Sprintf("testing_%s", tc.protocol),
508 }
509 switch network {
510 case "default":
511 setAutoAssignedPorts(DefaultNetwork, &cfg)
512 case "tcpV4":
513 setAutoAssignedPorts(NetworkTCPV4, &cfg)
514 default:
515 require.Fail(t, "unrecognized network %q", network)
516 }
517 srv, err := New(cfg)
518 require.NoError(t, err)
519
520 errChan := make(chan error, 1)
521 var wg sync.WaitGroup
522 t.Cleanup(wg.Wait)
523 wg.Add(1)
524 go func() {
525 defer wg.Done()
526 errChan <- srv.Run()
527 }()
528
529 switch tc.protocol {
530 case "http":
531 require.NoError(t, srv.httpListener.Close())
532 case "grpc":
533 require.NoError(t, srv.grpcListener.Close())
534 default:
535 require.Fail(t, fmt.Sprintf("unrecognized protocol %q", tc.protocol))
536 }
537 require.NotNil(t, <-errChan)
538
539 // So that address is freed for further tests.
540 srv.GRPC.Stop()
541 })
542 }
543 }
544}
545

Callers

nothing calls this directly

Calls 9

SetMethod · 0.95
setAutoAssignedPortsFunction · 0.85
RunMethod · 0.80
FailMethod · 0.80
NewFunction · 0.70
AddMethod · 0.65
DoneMethod · 0.65
CloseMethod · 0.65
StopMethod · 0.65

Tested by

no test coverage detected