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

Method TestStopAbortsBlockingGRPCCall

test/gracefulstop_test.go:268–302  ·  view source on GitHub ↗

TestStopAbortsBlockingGRPCCall ensures that when Stop() is called while an ongoing RPC is blocking that: - Stop() returns - and the RPC fails with an connection closed error on the client-side

(t *testing.T)

Source from the content-addressed store, hash-verified

266// - Stop() returns
267// - and the RPC fails with an connection closed error on the client-side
268func (s) TestStopAbortsBlockingGRPCCall(t *testing.T) {
269 unblockGRPCCall := make(chan struct{})
270 grpcCallExecuting := make(chan struct{})
271 ss := &stubserver.StubServer{
272 UnaryCallF: func(context.Context, *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
273 close(grpcCallExecuting)
274 <-unblockGRPCCall
275 return &testpb.SimpleResponse{}, nil
276 },
277 }
278
279 err := ss.Start(nil)
280 if err != nil {
281 t.Fatalf("StubServer.start failed: %s", err)
282 }
283 t.Cleanup(ss.Stop)
284
285 grpcClientCallReturned := make(chan struct{})
286 go func() {
287 clt := ss.Client
288 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
289 defer cancel()
290 _, err := clt.UnaryCall(ctx, &testpb.SimpleRequest{})
291 if err == nil || !isConnClosedErr(err) {
292 t.Errorf("expected rpc to fail with connection closed error, got: %v", err)
293 }
294 close(grpcClientCallReturned)
295 }()
296
297 <-grpcCallExecuting
298 ss.S.Stop()
299
300 unblockGRPCCall <- struct{}{}
301 <-grpcClientCallReturned
302}
303
304// TestServeHTTP_GracefulStop verifies that calling GracefulStop on a server
305// using ServeHTTP returns properly.

Callers

nothing calls this directly

Calls 6

StartMethod · 0.95
isConnClosedErrFunction · 0.85
FatalfMethod · 0.65
UnaryCallMethod · 0.65
ErrorfMethod · 0.65
StopMethod · 0.65

Tested by

no test coverage detected