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

Method TestHealthStreamNoOtelErrorLog

stats/opentelemetry/e2e_test.go:2081–2123  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2079}
2080
2081func (s) TestHealthStreamNoOtelErrorLog(t *testing.T) {
2082 mo, _ := defaultMetricsOptions(t, nil)
2083 to, _ := defaultTraceOptions(t)
2084 otelOptions := opentelemetry.Options{
2085 MetricsOptions: *mo,
2086 TraceOptions: *to,
2087 }
2088
2089 healthcheck := health.NewServer()
2090
2091 backend := stubserver.StartTestService(t, &stubserver.StubServer{
2092 EmptyCallF: func(_ context.Context, _ *testpb.Empty) (*testpb.Empty, error) {
2093 return &testpb.Empty{}, nil
2094 },
2095 }, stubserver.RegisterServiceServerOption(func(s grpc.ServiceRegistrar) {
2096 healthgrpc.RegisterHealthServer(s, healthcheck)
2097 }))
2098 defer backend.Stop()
2099
2100 healthcheck.SetServingStatus("", healthpb.HealthCheckResponse_SERVING)
2101
2102 // Dial with healthCheckConfig to trigger the internal health stream.
2103 sc := `{"loadBalancingConfig": [{"round_robin":{}}], "healthCheckConfig": {"serviceName": ""}}`
2104 dopts := []grpc.DialOption{
2105 grpc.WithTransportCredentials(insecure.NewCredentials()),
2106 opentelemetry.DialOption(otelOptions),
2107 grpc.WithDefaultServiceConfig(sc),
2108 }
2109
2110 cc, err := grpc.NewClient(backend.Address, dopts...)
2111 if err != nil {
2112 t.Fatalf("Failed to create client: %v", err)
2113 }
2114 defer cc.Close()
2115
2116 // Perform an RPC to ensure the subchannel connects and health stream initializes.
2117 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
2118 defer cancel()
2119 client := testgrpc.NewTestServiceClient(cc)
2120 if _, err := client.EmptyCall(ctx, &testpb.Empty{}); err != nil {
2121 t.Fatalf("EmptyCall failed: %v", err)
2122 }
2123}
2124
2125// errorConn wraps a standard net.Conn to allow manual error injection.
2126// It is used to simulate transport-level failures (like ECONNRESET) that

Callers

nothing calls this directly

Calls 15

SetServingStatusMethod · 0.95
EmptyCallMethod · 0.95
NewServerFunction · 0.92
StartTestServiceFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
DialOptionFunction · 0.92
WithDefaultServiceConfigFunction · 0.92
NewClientFunction · 0.92
defaultMetricsOptionsFunction · 0.85
defaultTraceOptionsFunction · 0.85

Tested by

no test coverage detected