@@ -29,6 +29,7 @@ import (
2929 "go.uber.org/multierr"
3030
3131 "nhooyr.io/websocket"
32+ "nhooyr.io/websocket/internal/wsecho"
3233 "nhooyr.io/websocket/wsjson"
3334 "nhooyr.io/websocket/wspb"
3435)
@@ -966,7 +967,7 @@ func TestAutobahn(t *testing.T) {
966967
967968 ctx := r .Context ()
968969 if testingClient {
969- echoLoop (r .Context (), c )
970+ wsecho . Loop (r .Context (), c )
970971 return nil
971972 }
972973
@@ -1007,7 +1008,7 @@ func TestAutobahn(t *testing.T) {
10071008 return
10081009 }
10091010
1010- echoLoop (ctx , c )
1011+ wsecho . Loop (ctx , c )
10111012 }
10121013 t .Run (name , func (t * testing.T ) {
10131014 t .Parallel ()
@@ -1849,47 +1850,6 @@ func TestAutobahn(t *testing.T) {
18491850 })
18501851}
18511852
1852- func echoLoop (ctx context.Context , c * websocket.Conn ) {
1853- defer c .Close (websocket .StatusInternalError , "" )
1854-
1855- c .SetReadLimit (1 << 40 )
1856-
1857- ctx , cancel := context .WithTimeout (ctx , time .Minute )
1858- defer cancel ()
1859-
1860- b := make ([]byte , 32768 )
1861- echo := func () error {
1862- typ , r , err := c .Reader (ctx )
1863- if err != nil {
1864- return err
1865- }
1866-
1867- w , err := c .Writer (ctx , typ )
1868- if err != nil {
1869- return err
1870- }
1871-
1872- _ , err = io .CopyBuffer (w , r , b )
1873- if err != nil {
1874- return err
1875- }
1876-
1877- err = w .Close ()
1878- if err != nil {
1879- return err
1880- }
1881-
1882- return nil
1883- }
1884-
1885- for {
1886- err := echo ()
1887- if err != nil {
1888- return
1889- }
1890- }
1891- }
1892-
18931853func assertCloseStatus (err error , code websocket.StatusCode ) error {
18941854 var cerr websocket.CloseError
18951855 if ! errors .As (err , & cerr ) {
@@ -1898,24 +1858,6 @@ func assertCloseStatus(err error, code websocket.StatusCode) error {
18981858 return assertEqualf (code , cerr .Code , "unexpected status code" )
18991859}
19001860
1901- func assertJSONRead (ctx context.Context , c * websocket.Conn , exp interface {}) (err error ) {
1902- var act interface {}
1903- err = wsjson .Read (ctx , c , & act )
1904- if err != nil {
1905- return err
1906- }
1907-
1908- return assertEqualf (exp , act , "unexpected JSON" )
1909- }
1910-
1911- func randBytes (n int ) []byte {
1912- return make ([]byte , n )
1913- }
1914-
1915- func randString (n int ) string {
1916- return string (randBytes (n ))
1917- }
1918-
19191861func assertEcho (ctx context.Context , c * websocket.Conn , typ websocket.MessageType , n int ) error {
19201862 p := randBytes (n )
19211863 err := c .Write (ctx , typ , p )
@@ -1949,13 +1891,6 @@ func assertSubprotocol(c *websocket.Conn, exp string) error {
19491891 return assertEqualf (exp , c .Subprotocol (), "unexpected subprotocol" )
19501892}
19511893
1952- func assertEqualf (exp , act interface {}, f string , v ... interface {}) error {
1953- if diff := cmpDiff (exp , act ); diff != "" {
1954- return fmt .Errorf (f + ": %v" , append (v , diff )... )
1955- }
1956- return nil
1957- }
1958-
19591894func assertNetConnRead (r io.Reader , exp string ) error {
19601895 act := make ([]byte , len (exp ))
19611896 _ , err := r .Read (act )
0 commit comments