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

Method TestTapTimeout

test/end2end_test.go:5377–5411  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

5375}
5376
5377func (s) TestTapTimeout(t *testing.T) {
5378 sopts := []grpc.ServerOption{
5379 grpc.InTapHandle(func(ctx context.Context, _ *tap.Info) (context.Context, error) {
5380 c, cancel := context.WithCancel(ctx)
5381 // Call cancel instead of setting a deadline so we can detect which error
5382 // occurred -- this cancellation (desired) or the client's deadline
5383 // expired (indicating this cancellation did not affect the RPC).
5384 time.AfterFunc(10*time.Millisecond, cancel)
5385 return c, nil
5386 }),
5387 }
5388
5389 ss := &stubserver.StubServer{
5390 EmptyCallF: func(ctx context.Context, _ *testpb.Empty) (*testpb.Empty, error) {
5391 <-ctx.Done()
5392 return nil, status.Error(codes.Canceled, ctx.Err().Error())
5393 },
5394 }
5395 if err := ss.Start(sopts); err != nil {
5396 t.Fatalf("Error starting endpoint server: %v", err)
5397 }
5398 defer ss.Stop()
5399
5400 // This was known to be flaky; test several times.
5401 for i := 0; i < 10; i++ {
5402 // Set our own deadline in case the server hangs.
5403 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
5404 res, err := ss.Client.EmptyCall(ctx, &testpb.Empty{})
5405 cancel()
5406 if s, ok := status.FromError(err); !ok || s.Code() != codes.Canceled {
5407 t.Fatalf("ss.Client.EmptyCall(ctx, _) = %v, %v; want nil, <status with Code()=Canceled>", res, err)
5408 }
5409 }
5410
5411}
5412
5413func (s) TestClientWriteFailsAfterServerClosesStream(t *testing.T) {
5414 ss := &stubserver.StubServer{

Callers

nothing calls this directly

Calls 9

StartMethod · 0.95
StopMethod · 0.95
InTapHandleFunction · 0.92
ErrMethod · 0.80
CodeMethod · 0.80
ErrorMethod · 0.65
FatalfMethod · 0.65
EmptyCallMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected