| 5375 | } |
| 5376 | |
| 5377 | func (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 | |
| 5413 | func (s) TestClientWriteFailsAfterServerClosesStream(t *testing.T) { |
| 5414 | ss := &stubserver.StubServer{ |