Skip to content

Commit bd9f64b

Browse files
committed
Translate the remaining useful Autobahn python tests
1 parent a681f25 commit bd9f64b

File tree

4 files changed

+750
-23
lines changed

4 files changed

+750
-23
lines changed

ci/test.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ argv=(
1111
"--format=short-verbose"
1212
--
1313
"-vet=off"
14+
-race
1415
)
15-
# Interactive usage does not want to turn off vet or use gotestsum by default.
16+
# Interactive usage does not want to turn off vet, use gotestsum or the
17+
# race detector by default.
1618
if [[ $# -gt 0 ]]; then
1719
argv=(go test "$@")
1820
fi
1921

2022
# We always want coverage and race detection.
2123
argv+=(
22-
-race
2324
"-coverprofile=ci/out/coverage.prof"
2425
"-coverpkg=./..."
2526
)

export_test.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type (
1515
const (
1616
OpClose = OpCode(opClose)
1717
OpBinary = OpCode(opBinary)
18+
OpText = OpCode(opText)
1819
OpPing = OpCode(opPing)
1920
OpPong = OpCode(opPong)
2021
OpContinuation = OpCode(opContinuation)
@@ -40,17 +41,38 @@ func (c *Conn) WriteFrame(ctx context.Context, fin bool, opc OpCode, p []byte) (
4041
return c.writeFrame(ctx, fin, opcode(opc), p)
4142
}
4243

43-
func (c *Conn) WriteHeader(ctx context.Context, fin bool, opc OpCode, lenp int64) error {
44+
// header represents a WebSocket frame header.
45+
// See https://tools.ietf.org/html/rfc6455#section-5.2
46+
type Header struct {
47+
Fin bool
48+
Rsv1 bool
49+
Rsv2 bool
50+
Rsv3 bool
51+
OpCode OpCode
52+
53+
PayloadLength int64
54+
}
55+
56+
func (c *Conn) WriteHeader(ctx context.Context, h Header) error {
4457
headerBytes := writeHeader(c.writeHeaderBuf, header{
45-
fin: fin,
46-
opcode: opcode(opc),
47-
payloadLength: lenp,
58+
fin: h.Fin,
59+
rsv1: h.Rsv1,
60+
rsv2: h.Rsv2,
61+
rsv3: h.Rsv3,
62+
opcode: opcode(h.OpCode),
63+
payloadLength: h.PayloadLength,
4864
masked: c.client,
4965
})
5066
_, err := c.bw.Write(headerBytes)
5167
if err != nil {
5268
return xerrors.Errorf("failed to write header: %w", err)
5369
}
70+
if h.Fin {
71+
err = c.Flush()
72+
if err != nil {
73+
return err
74+
}
75+
}
5476
return nil
5577
}
5678

@@ -96,3 +118,7 @@ func (c *Conn) WriteClose(ctx context.Context, code StatusCode, reason string) (
96118
}
97119
return b, nil
98120
}
121+
122+
func ParseClosePayload(p []byte) (CloseError, error) {
123+
return parseClosePayload(p)
124+
}

websocket_bench_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import (
55
"io"
66
"io/ioutil"
77
"net/http"
8-
"nhooyr.io/websocket"
98
"strconv"
109
"strings"
1110
"testing"
1211
"time"
13-
)
1412

13+
"nhooyr.io/websocket"
14+
)
1515

1616
func BenchmarkConn(b *testing.B) {
1717
sizes := []int{
@@ -116,7 +116,6 @@ func benchConn(b *testing.B, echo, stream bool, size int) {
116116
c.Close(websocket.StatusNormalClosure, "")
117117
}
118118

119-
120119
func discardLoop(ctx context.Context, c *websocket.Conn) {
121120
defer c.Close(websocket.StatusInternalError, "")
122121

0 commit comments

Comments
 (0)