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

Method TestOpenCensusIntegration

gcp/observability/observability_test.go:364–477  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

362}
363
364func (s) TestOpenCensusIntegration(t *testing.T) {
365 defaultMetricsReportingInterval = time.Millisecond * 100
366 fe := &fakeOpenCensusExporter{SeenViews: make(map[string]string), t: t}
367
368 defer func(ne func(config *config) (tracingMetricsExporter, error)) {
369 newExporter = ne
370 }(newExporter)
371
372 newExporter = func(*config) (tracingMetricsExporter, error) {
373 return fe, nil
374 }
375
376 openCensusOnConfig := &config{
377 ProjectID: "fake",
378 CloudMonitoring: &cloudMonitoring{},
379 CloudTrace: &cloudTrace{
380 SamplingRate: 1.0,
381 },
382 }
383 cleanup, err := setupObservabilitySystemWithConfig(openCensusOnConfig)
384 if err != nil {
385 t.Fatalf("error setting up observability %v", err)
386 }
387 defer cleanup()
388
389 ss := &stubserver.StubServer{
390 UnaryCallF: func(context.Context, *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
391 return &testpb.SimpleResponse{}, nil
392 },
393 FullDuplexCallF: func(stream testgrpc.TestService_FullDuplexCallServer) error {
394 for {
395 _, err := stream.Recv()
396 if err == io.EOF {
397 return nil
398 }
399 }
400 },
401 }
402 if err := ss.Start(nil); err != nil {
403 t.Fatalf("Error starting endpoint server: %v", err)
404 }
405 defer ss.Stop()
406
407 for i := 0; i < defaultRequestCount; i++ {
408 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
409 defer cancel()
410 if _, err := ss.Client.UnaryCall(ctx, &testpb.SimpleRequest{Payload: &testpb.Payload{Body: testOkPayload}}); err != nil {
411 t.Fatalf("Unexpected error from UnaryCall: %v", err)
412 }
413 }
414 t.Logf("unary call passed count=%v", defaultRequestCount)
415 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
416 defer cancel()
417 stream, err := ss.Client.FullDuplexCall(ctx)
418 if err != nil {
419 t.Fatalf("ss.Client.FullDuplexCall failed: %f", err)
420 }
421

Callers

nothing calls this directly

Calls 11

StartMethod · 0.95
StopMethod · 0.95
ErrMethod · 0.80
FatalfMethod · 0.65
RecvMethod · 0.65
UnaryCallMethod · 0.65
LogfMethod · 0.65
FullDuplexCallMethod · 0.65
CloseSendMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected