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

Function TestServeControlStream

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

Source from the content-addressed store, hash-verified

356}
357
358func TestServeControlStream(t *testing.T) {
359 http2Conn, edgeConn := newTestHTTP2Connection()
360
361 rpcClientFactory := mockRPCClientFactory{
362 registered: make(chan struct{}),
363 unregistered: make(chan struct{}),
364 }
365
366 obs := NewObserver(&log, &log)
367 controlStream := NewControlStream(
368 obs,
369 mockConnectedFuse{},
370 &TunnelProperties{},
371 1,
372 nil,
373 rpcClientFactory.newMockRPCClient,
374 1*time.Second,
375 nil,
376 1*time.Second,
377 HTTP2,
378 )
379 http2Conn.controlStreamHandler = controlStream
380
381 ctx, cancel := context.WithCancel(t.Context())
382 var wg sync.WaitGroup
383 wg.Add(1)
384 go func() {
385 defer wg.Done()
386 _ = http2Conn.Serve(ctx)
387 }()
388
389 req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://localhost:8080/", nil)
390 require.NoError(t, err)
391 req.Header.Set(InternalUpgradeHeader, ControlStreamUpgrade)
392
393 edgeHTTP2Conn, err := testTransport.NewClientConn(edgeConn)
394 require.NoError(t, err)
395
396 wg.Add(1)
397 go func() {
398 defer wg.Done()
399 // nolint: bodyclose
400 _, _ = edgeHTTP2Conn.RoundTrip(req)
401 }()
402
403 <-rpcClientFactory.registered
404 cancel()
405 <-rpcClientFactory.unregistered
406 assert.False(t, http2Conn.stoppedGracefully)
407
408 wg.Wait()
409}
410
411func TestFailRegistration(t *testing.T) {
412 http2Conn, edgeConn := newTestHTTP2Connection()

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected