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

Function TestFailRegistration

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

Source from the content-addressed store, hash-verified

409}
410
411func TestFailRegistration(t *testing.T) {
412 http2Conn, edgeConn := newTestHTTP2Connection()
413
414 rpcClientFactory := mockRPCClientFactory{
415 shouldFail: errDuplicationConnection,
416 registered: make(chan struct{}),
417 unregistered: make(chan struct{}),
418 }
419
420 obs := NewObserver(&log, &log)
421 controlStream := NewControlStream(
422 obs,
423 mockConnectedFuse{},
424 &TunnelProperties{},
425 http2Conn.connIndex,
426 nil,
427 rpcClientFactory.newMockRPCClient,
428 1*time.Second,
429 nil,
430 1*time.Second,
431 HTTP2,
432 )
433 http2Conn.controlStreamHandler = controlStream
434
435 ctx, cancel := context.WithCancel(t.Context())
436 var wg sync.WaitGroup
437 wg.Add(1)
438 go func() {
439 defer wg.Done()
440 _ = http2Conn.Serve(ctx)
441 }()
442
443 req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://localhost:8080/", nil)
444 require.NoError(t, err)
445 req.Header.Set(InternalUpgradeHeader, ControlStreamUpgrade)
446
447 edgeHTTP2Conn, err := testTransport.NewClientConn(edgeConn)
448 require.NoError(t, err)
449 resp, err := edgeHTTP2Conn.RoundTrip(req)
450 require.NoError(t, err)
451 defer resp.Body.Close()
452 require.Equal(t, http.StatusBadGateway, resp.StatusCode)
453
454 require.Error(t, http2Conn.controlStreamErr)
455 cancel()
456 wg.Wait()
457}
458
459func TestGracefulShutdownHTTP2(t *testing.T) {
460 http2Conn, edgeConn := newTestHTTP2Connection()

Callers

nothing calls this directly

Calls 12

newTestHTTP2ConnectionFunction · 0.85
NewObserverFunction · 0.85
NewControlStreamFunction · 0.85
WaitMethod · 0.80
ContextMethod · 0.65
AddMethod · 0.65
ServeMethod · 0.65
CloseMethod · 0.65
EqualMethod · 0.65
SetMethod · 0.45
RoundTripMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected