MCPcopy
hub / github.com/cloudflare/cloudflared / TestGracefulShutdownHTTP2

Function TestGracefulShutdownHTTP2

connection/http2_test.go:459–533  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

457}
458
459func TestGracefulShutdownHTTP2(t *testing.T) {
460 http2Conn, edgeConn := newTestHTTP2Connection()
461
462 rpcClientFactory := mockRPCClientFactory{
463 registered: make(chan struct{}),
464 unregistered: make(chan struct{}),
465 }
466 events := &eventCollectorSink{}
467
468 shutdownC := make(chan struct{})
469 obs := NewObserver(&log, &log)
470 obs.RegisterSink(events)
471 controlStream := NewControlStream(
472 obs,
473 mockConnectedFuse{},
474 &TunnelProperties{},
475 http2Conn.connIndex,
476 nil,
477 rpcClientFactory.newMockRPCClient,
478 1*time.Second,
479 shutdownC,
480 1*time.Second,
481 HTTP2,
482 )
483
484 http2Conn.controlStreamHandler = controlStream
485
486 ctx, cancel := context.WithCancel(t.Context())
487 var wg sync.WaitGroup
488 wg.Add(1)
489 go func() {
490 defer wg.Done()
491 _ = http2Conn.Serve(ctx)
492 }()
493
494 req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://localhost:8080/", nil)
495 require.NoError(t, err)
496 req.Header.Set(InternalUpgradeHeader, ControlStreamUpgrade)
497
498 edgeHTTP2Conn, err := testTransport.NewClientConn(edgeConn)
499 require.NoError(t, err)
500
501 wg.Add(1)
502 go func() {
503 defer wg.Done()
504 // nolint: bodyclose
505 _, _ = edgeHTTP2Conn.RoundTrip(req)
506 }()
507
508 select {
509 case <-rpcClientFactory.registered:
510 break // ok
511 case <-time.Tick(time.Second):
512 t.Fatal("timeout out waiting for registration")
513 }
514
515 // signal graceful shutdown
516 close(shutdownC)

Callers

nothing calls this directly

Calls 12

RegisterSinkMethod · 0.95
assertSawEventMethod · 0.95
newTestHTTP2ConnectionFunction · 0.85
NewObserverFunction · 0.85
NewControlStreamFunction · 0.85
WaitMethod · 0.80
ContextMethod · 0.65
AddMethod · 0.65
ServeMethod · 0.65
IsStoppedMethod · 0.65
SetMethod · 0.45
RoundTripMethod · 0.45

Tested by

no test coverage detected