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

Function TestStreamTCPConnection

ingress/origin_connection_test.go:36–69  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

34)
35
36func TestStreamTCPConnection(t *testing.T) {
37 cfdConn, originConn := net.Pipe()
38 tcpConn := tcpConnection{
39 Conn: cfdConn,
40 writeTimeout: 30 * time.Second,
41 }
42
43 eyeballConn, edgeConn := net.Pipe()
44
45 ctx, cancel := context.WithTimeout(context.Background(), testStreamTimeout)
46 defer cancel()
47
48 errGroup, ctx := errgroup.WithContext(ctx)
49 errGroup.Go(func() error {
50 _, err := eyeballConn.Write(testMessage)
51 require.NoError(t, err)
52
53 readBuffer := make([]byte, len(testResponse))
54 _, err = eyeballConn.Read(readBuffer)
55 require.NoError(t, err)
56
57 require.Equal(t, testResponse, readBuffer)
58
59 return nil
60 })
61 errGroup.Go(func() error {
62 echoTCPOrigin(t, originConn)
63 _ = originConn.Close()
64 return nil
65 })
66
67 tcpConn.Stream(ctx, edgeConn, TestLogger)
68 require.NoError(t, errGroup.Wait())
69}
70
71func TestDefaultStreamWSOverTCPConnection(t *testing.T) {
72 cfdConn, originConn := net.Pipe()

Callers

nothing calls this directly

Calls 7

StreamMethod · 0.95
echoTCPOriginFunction · 0.85
WaitMethod · 0.80
WriteMethod · 0.65
EqualMethod · 0.65
CloseMethod · 0.65
ReadMethod · 0.45

Tested by

no test coverage detected