diff --git a/conn_test.go b/conn_test.go index 535afe247e6b759fe117e94c8beead9a41a8888a..28da3c0788213a08757e7f80250c8297c0cf0fe1 100644 --- a/conn_test.go +++ b/conn_test.go @@ -337,8 +337,10 @@ func newConnTest(t testing.TB, dialOpts *websocket.DialOptions, acceptOpts *webs tt = &connTest{t: t, ctx: ctx} tt.appendDone(cancel) - c1, c2, err := wstest.Pipe(dialOpts, acceptOpts) - assert.Success(tt.t, err) + c1, c2 = wstest.Pipe(dialOpts, acceptOpts) + if xrand.Bool() { + c1, c2 = c2, c1 + } tt.appendDone(func() { c2.Close(websocket.StatusInternalError, "") c1.Close(websocket.StatusInternalError, "") diff --git a/internal/test/wstest/pipe.go b/internal/test/wstest/pipe.go index 0a2899ee1bba1c0131a8b5881c396f463afd7f12..1534f3168153134fa1cb3d178cdb964174e95441 100644 --- a/internal/test/wstest/pipe.go +++ b/internal/test/wstest/pipe.go @@ -5,26 +5,19 @@ package wstest import ( "bufio" "context" - "fmt" "net" "net/http" "net/http/httptest" "nhooyr.io/websocket" - "nhooyr.io/websocket/internal/errd" - "nhooyr.io/websocket/internal/test/xrand" ) // Pipe is used to create an in memory connection // between two websockets analogous to net.Pipe. -func Pipe(dialOpts *websocket.DialOptions, acceptOpts *websocket.AcceptOptions) (_ *websocket.Conn, _ *websocket.Conn, err error) { - defer errd.Wrap(&err, "failed to create ws pipe") - - var serverConn *websocket.Conn - var acceptErr error +func Pipe(dialOpts *websocket.DialOptions, acceptOpts *websocket.AcceptOptions) (clientConn, serverConn *websocket.Conn) { tt := fakeTransport{ h: func(w http.ResponseWriter, r *http.Request) { - serverConn, acceptErr = websocket.Accept(w, r, acceptOpts) + serverConn, _ = websocket.Accept(w, r, acceptOpts) }, } @@ -36,19 +29,8 @@ func Pipe(dialOpts *websocket.DialOptions, acceptOpts *websocket.AcceptOptions) Transport: tt, } - clientConn, _, err := websocket.Dial(context.Background(), "ws://example.com", dialOpts) - if err != nil { - return nil, nil, fmt.Errorf("failed to dial with fake transport: %w", err) - } - - if serverConn == nil { - return nil, nil, fmt.Errorf("failed to get server conn from fake transport: %w", acceptErr) - } - - if xrand.Bool() { - return serverConn, clientConn, nil - } - return clientConn, serverConn, nil + clientConn, _, _ = websocket.Dial(context.Background(), "ws://example.com", dialOpts) + return clientConn, serverConn } type fakeTransport struct {