| 34 | ) |
| 35 | |
| 36 | func 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 | |
| 71 | func TestDefaultStreamWSOverTCPConnection(t *testing.T) { |
| 72 | cfdConn, originConn := net.Pipe() |