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

Method TestClientUpdatesParamsAfterGoAway

dial_test.go:231–295  ·  dial_test.go::s.TestClientUpdatesParamsAfterGoAway
(t *testing.T)

Source from the content-addressed store, hash-verified

229}
230
231func (s) TestClientUpdatesParamsAfterGoAway(t *testing.T) {
232 grpctest.ExpectError("Client received GoAway with error code ENHANCE_YOUR_CALM and debug data equal to ASCII \"too_many_pings\"")
233
234 lis, err := net.Listen("tcp", "localhost:0")
235 if err != nil {
236 t.Fatalf("Failed to listen. Err: %v", err)
237 }
238 defer lis.Close()
239 connected := grpcsync.NewEvent()
240 defer connected.Fire()
241 go func() {
242 conn, err := lis.Accept()
243 if err != nil {
244 t.Errorf("error accepting connection: %v", err)
245 return
246 }
247 defer conn.Close()
248 f := http2.NewFramer(conn, conn)
249 // Start a goroutine to read from the conn to prevent the client from
250 // blocking after it writes its preface.
251 go func() {
252 for {
253 if _, err := f.ReadFrame(); err != nil {
254 return
255 }
256 }
257 }()
258 if err := f.WriteSettings(http2.Setting{}); err != nil {
259 t.Errorf("error writing settings: %v", err)
260 return
261 }
262 <-connected.Done()
263 if err := f.WriteGoAway(0, http2.ErrCodeEnhanceYourCalm, []byte("too_many_pings")); err != nil {
264 t.Errorf("error writing GOAWAY: %v", err)
265 return
266 }
267 }()
268 addr := lis.Addr().String()
269 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
270 defer cancel()
271 cc, err := DialContext(ctx, addr, WithBlock(), WithTransportCredentials(insecure.NewCredentials()), WithKeepaliveParams(keepalive.ClientParameters{
272 Time: 10 * time.Second,
273 Timeout: 100 * time.Millisecond,
274 PermitWithoutStream: true,
275 }))
276 if err != nil {
277 t.Fatalf("DialContext(%s) failed: %v, want: nil", addr, err)
278 }
279 defer cc.Close()
280 connected.Fire()
281 for {
282 time.Sleep(10 * time.Millisecond)
283 cc.mu.RLock()
284 v := cc.keepaliveParams.Time
285 cc.mu.RUnlock()
286 if v == 20*time.Second {
287 // Success
288 return

Callers

nothing calls this directly

Calls 15

FireMethod · 0.95
DoneMethod · 0.95
ExpectErrorFunction · 0.92
NewEventFunction · 0.92
NewCredentialsFunction · 0.92
DialContextFunction · 0.85
WithBlockFunction · 0.85
WithTransportCredentialsFunction · 0.85
WithKeepaliveParamsFunction · 0.85
ErrMethod · 0.80
FatalfMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected