good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
websocket
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
websocket
Commits
e92b5474
Unverified
Commit
e92b5474
authored
5 years ago
by
Anmol Sethi
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #202 from nhooyr/wstest
Simplify wstest.Pipe
parents
108d760d
97345d80
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
conn_test.go
+4
-2
4 additions, 2 deletions
conn_test.go
internal/test/wstest/pipe.go
+4
-22
4 additions, 22 deletions
internal/test/wstest/pipe.go
with
8 additions
and
24 deletions
conn_test.go
+
4
−
2
View file @
e92b5474
...
...
@@ -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
,
""
)
...
...
This diff is collapsed.
Click to expand it.
internal/test/wstest/pipe.go
+
4
−
22
View file @
e92b5474
...
...
@@ -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
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment