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

Function testCancelNoIO

test/end2end_test.go:3128–3181  ·  view source on GitHub ↗
(t *testing.T, e env)

Source from the content-addressed store, hash-verified

3126}
3127
3128func testCancelNoIO(t *testing.T, e env) {
3129 te := newTest(t, e)
3130 te.declareLogNoise("http2Client.notifyError got notified that the client transport was broken")
3131 te.maxStream = 1 // Only allows 1 live stream per server transport.
3132 te.startServer(&testServer{security: e.security})
3133 defer te.tearDown()
3134
3135 cc := te.clientConn()
3136 tc := testgrpc.NewTestServiceClient(cc)
3137
3138 // Start one blocked RPC for which we'll never send streaming
3139 // input. This will consume the 1 maximum concurrent streams,
3140 // causing future RPCs to hang.
3141 ctx, cancelFirst := context.WithTimeout(context.Background(), defaultTestTimeout)
3142 _, err := tc.StreamingInputCall(ctx)
3143 if err != nil {
3144 t.Fatalf("%v.StreamingInputCall(_) = _, %v, want _, <nil>", tc, err)
3145 }
3146
3147 // Loop until the ClientConn receives the initial settings
3148 // frame from the server, notifying it about the maximum
3149 // concurrent streams. We know when it's received it because
3150 // an RPC will fail with codes.DeadlineExceeded instead of
3151 // succeeding.
3152 // TODO(bradfitz): add internal test hook for this (Issue 534)
3153 for {
3154 ctx, cancelSecond := context.WithTimeout(context.Background(), defaultTestShortTimeout)
3155 _, err := tc.StreamingInputCall(ctx)
3156 cancelSecond()
3157 if err == nil {
3158 continue
3159 }
3160 if status.Code(err) == codes.DeadlineExceeded {
3161 break
3162 }
3163 t.Fatalf("%v.StreamingInputCall(_) = _, %v, want _, %s", tc, err, codes.DeadlineExceeded)
3164 }
3165 // If there are any RPCs in flight before the client receives
3166 // the max streams setting, let them be expired.
3167 // TODO(bradfitz): add internal test hook for this (Issue 534)
3168 time.Sleep(50 * time.Millisecond)
3169
3170 go func() {
3171 time.Sleep(50 * time.Millisecond)
3172 cancelFirst()
3173 }()
3174
3175 // This should be blocked until the 1st is canceled, then succeed.
3176 ctx, cancelThird := context.WithTimeout(context.Background(), defaultTestShortTimeout)
3177 if _, err := tc.StreamingInputCall(ctx); err != nil {
3178 t.Errorf("%v.StreamingInputCall(_) = _, %v, want _, <nil>", tc, err)
3179 }
3180 cancelThird()
3181}
3182
3183// The following tests the gRPC streaming RPC implementations.
3184// TODO(zhaoq): Have better coverage on error cases.

Callers 1

TestCancelNoIOMethod · 0.85

Calls 9

StreamingInputCallMethod · 0.95
declareLogNoiseMethod · 0.80
CodeMethod · 0.80
newTestFunction · 0.70
FatalfMethod · 0.65
ErrorfMethod · 0.65
startServerMethod · 0.45
tearDownMethod · 0.45
clientConnMethod · 0.45

Tested by

no test coverage detected