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

Function testServerGoAway

test/goaway_test.go:214–250  ·  view source on GitHub ↗
(t *testing.T, e env)

Source from the content-addressed store, hash-verified

212}
213
214func testServerGoAway(t *testing.T, e env) {
215 te := newTest(t, e)
216 te.userAgent = testAppUA
217 te.startServer(&testServer{security: e.security})
218 defer te.tearDown()
219
220 cc := te.clientConn()
221 tc := testgrpc.NewTestServiceClient(cc)
222 // Finish an RPC to make sure the connection is good.
223 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
224 defer cancel()
225 if _, err := tc.EmptyCall(ctx, &testpb.Empty{}, grpc.WaitForReady(true)); err != nil {
226 t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want _, <nil>", err)
227 }
228 ch := make(chan struct{})
229 go func() {
230 te.srv.GracefulStop()
231 close(ch)
232 }()
233 // Loop until the server side GoAway signal is propagated to the client.
234 for {
235 ctx, cancel := context.WithTimeout(context.Background(), defaultTestShortTimeout)
236 if _, err := tc.EmptyCall(ctx, &testpb.Empty{}); err != nil && status.Code(err) != codes.DeadlineExceeded {
237 cancel()
238 break
239 }
240 cancel()
241 }
242 // A new RPC should fail.
243 ctx, cancel = context.WithTimeout(context.Background(), defaultTestTimeout)
244 defer cancel()
245 if _, err := tc.EmptyCall(ctx, &testpb.Empty{}); status.Code(err) != codes.Unavailable && status.Code(err) != codes.Internal {
246 t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want _, %s or %s", err, codes.Unavailable, codes.Internal)
247 }
248 <-ch
249 awaitNewConnLogOutput()
250}
251
252func (s) TestServerGoAwayPendingRPC(t *testing.T) {
253 for _, e := range listTestEnv() {

Callers 1

TestServerGoAwayMethod · 0.85

Calls 10

EmptyCallMethod · 0.95
WaitForReadyFunction · 0.92
CodeFunction · 0.92
awaitNewConnLogOutputFunction · 0.85
newTestFunction · 0.70
FatalfMethod · 0.65
GracefulStopMethod · 0.65
startServerMethod · 0.45
tearDownMethod · 0.45
clientConnMethod · 0.45

Tested by

no test coverage detected