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
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
github
nhooyr
websocket
Commits
9e32354f
Unverified
Commit
9e32354f
authored
Feb 6, 2020
by
Anmol Sethi
Browse files
Options
Downloads
Patches
Plain Diff
Fix randString method in tests
parent
b6b56b74
No related branches found
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
assert_test.go
+1
-0
1 addition, 0 deletions
assert_test.go
ci/image/Dockerfile
+1
-1
1 addition, 1 deletion
ci/image/Dockerfile
conn_test.go
+41
-11
41 additions, 11 deletions
conn_test.go
internal/errd/wrap.go
+32
-2
32 additions, 2 deletions
internal/errd/wrap.go
write.go
+1
-1
1 addition, 1 deletion
write.go
with
76 additions
and
15 deletions
assert_test.go
+
1
−
0
View file @
9e32354f
...
...
@@ -45,6 +45,7 @@ func assertJSONRead(t *testing.T, ctx context.Context, c *websocket.Conn, exp in
func
randString
(
t
*
testing
.
T
,
n
int
)
string
{
s
:=
strings
.
ToValidUTF8
(
string
(
randBytes
(
t
,
n
)),
"_"
)
s
=
strings
.
ReplaceAll
(
s
,
"
\x00
"
,
"_"
)
if
len
(
s
)
>
n
{
return
s
[
:
n
]
}
...
...
This diff is collapsed.
Click to expand it.
ci/image/Dockerfile
+
1
−
1
View file @
9e32354f
FROM
golang:1
RUN
apt-get update
RUN
apt-get
install
-y
chromium
RUN
apt-get
install
-y
chromium
npm
ENV
GOFLAGS="-mod=readonly"
ENV
PAGER=cat
...
...
This diff is collapsed.
Click to expand it.
conn_test.go
+
41
−
11
View file @
9e32354f
...
...
@@ -18,6 +18,38 @@ import (
"nhooyr.io/websocket"
)
func
TestFuzz
(
t
*
testing
.
T
)
{
t
.
Parallel
()
s
,
closeFn
:=
testServer
(
t
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
c
,
err
:=
websocket
.
Accept
(
w
,
r
,
&
websocket
.
AcceptOptions
{
CompressionOptions
:
websocket
.
CompressionOptions
{
Mode
:
websocket
.
CompressionContextTakeover
,
},
})
assert
.
Success
(
t
,
"accept"
,
err
)
defer
c
.
Close
(
websocket
.
StatusInternalError
,
""
)
err
=
echoLoop
(
r
.
Context
(),
c
)
assertCloseStatus
(
t
,
websocket
.
StatusNormalClosure
,
err
)
},
false
)
defer
closeFn
()
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Minute
)
defer
cancel
()
opts
:=
&
websocket
.
DialOptions
{
CompressionOptions
:
websocket
.
CompressionOptions
{
Mode
:
websocket
.
CompressionContextTakeover
,
},
}
opts
.
HTTPClient
=
s
.
Client
()
c
,
_
,
err
:=
websocket
.
Dial
(
ctx
,
wsURL
(
s
),
opts
)
assert
.
Success
(
t
,
"dial"
,
err
)
assertJSONEcho
(
t
,
ctx
,
c
,
8393
)
}
func
TestConn
(
t
*
testing
.
T
)
{
t
.
Parallel
()
...
...
@@ -25,23 +57,18 @@ func TestConn(t *testing.T) {
s
,
closeFn
:=
testServer
(
t
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
c
,
err
:=
websocket
.
Accept
(
w
,
r
,
&
websocket
.
AcceptOptions
{
Subprotocols
:
[]
string
{
"echo"
},
InsecureSkipVerify
:
true
,
CompressionOptions
:
websocket
.
CompressionOptions
{
Mode
:
websocket
.
CompressionContextTakeover
,
Threshold
:
1
,
},
})
assert
.
Success
(
t
,
"accept"
,
err
)
defer
c
.
Close
(
websocket
.
StatusInternalError
,
""
)
err
=
echoLoop
(
r
.
Context
(),
c
)
t
.
Logf
(
"server: %v"
,
err
)
assertCloseStatus
(
t
,
websocket
.
StatusNormalClosure
,
err
)
},
false
)
defer
closeFn
()
wsURL
:=
strings
.
Replace
(
s
.
URL
,
"http"
,
"ws"
,
1
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Minute
)
defer
cancel
()
...
...
@@ -49,14 +76,13 @@ func TestConn(t *testing.T) {
Subprotocols
:
[]
string
{
"echo"
},
CompressionOptions
:
websocket
.
CompressionOptions
{
Mode
:
websocket
.
CompressionContextTakeover
,
Threshold
:
1
,
},
}
opts
.
HTTPClient
=
s
.
Client
()
c
,
_
,
err
:=
websocket
.
Dial
(
ctx
,
wsURL
,
opts
)
c
,
_
,
err
:=
websocket
.
Dial
(
ctx
,
wsURL
(
s
)
,
opts
)
assert
.
Success
(
t
,
"dial"
,
err
)
assertJSONEcho
(
t
,
ctx
,
c
,
2
)
assertJSONEcho
(
t
,
ctx
,
c
,
8393
)
})
}
...
...
@@ -149,3 +175,7 @@ func echoLoop(ctx context.Context, c *websocket.Conn) error {
}
}
}
func
wsURL
(
s
*
httptest
.
Server
)
string
{
return
strings
.
Replace
(
s
.
URL
,
"http"
,
"ws"
,
1
)
}
This diff is collapsed.
Click to expand it.
internal/errd/wrap.go
+
32
−
2
View file @
9e32354f
package
errd
import
"golang.org/x/xerrors"
import
(
"fmt"
"golang.org/x/xerrors"
)
type
wrapError
struct
{
msg
string
err
error
frame
xerrors
.
Frame
}
func
(
e
*
wrapError
)
Error
()
string
{
return
fmt
.
Sprint
(
e
)
}
func
(
e
*
wrapError
)
Format
(
s
fmt
.
State
,
v
rune
)
{
xerrors
.
FormatError
(
e
,
s
,
v
)
}
func
(
e
*
wrapError
)
FormatError
(
p
xerrors
.
Printer
)
(
next
error
)
{
p
.
Print
(
e
.
msg
)
e
.
frame
.
Format
(
p
)
return
e
.
err
}
func
(
e
*
wrapError
)
Unwrap
()
error
{
return
e
.
err
}
// Wrap wraps err with xerrors.Errorf if err is non nil.
// Intended for use with defer and a named error return.
// Inspired by https://github.com/golang/go/issues/32676.
func
Wrap
(
err
*
error
,
f
string
,
v
...
interface
{})
{
if
*
err
!=
nil
{
*
err
=
xerrors
.
Errorf
(
f
+
": %w"
,
append
(
v
,
*
err
)
...
)
*
err
=
&
wrapError
{
msg
:
fmt
.
Sprintf
(
f
,
v
...
),
err
:
*
err
,
frame
:
xerrors
.
Caller
(
1
),
}
}
}
This diff is collapsed.
Click to expand it.
write.go
+
1
−
1
View file @
9e32354f
...
...
@@ -145,7 +145,7 @@ func (mw *msgWriter) Write(p []byte) (_ int, err error) {
return
0
,
xerrors
.
New
(
"cannot use closed writer"
)
}
// TODO can make threshold detection robust across writes by writing to buf
f
er
// TODO can make threshold detection robust across writes by writing to buf
io writ
er
if
mw
.
flate
||
mw
.
c
.
flate
()
&&
len
(
p
)
>=
mw
.
c
.
flateThreshold
{
mw
.
ensureFlate
()
...
...
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