Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
nhooyr committed Apr 7, 2024
2 parents e3a2d32 + e87d61a commit bd07a64
Show file tree
Hide file tree
Showing 31 changed files with 868 additions and 331 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
- run: ./ci/fmt.sh
Expand All @@ -19,7 +19,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- run: go version
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
- run: ./ci/lint.sh
Expand All @@ -28,7 +28,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
- run: ./ci/test.sh
Expand All @@ -41,7 +41,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
- run: ./ci/bench.sh
10 changes: 5 additions & 5 deletions .github/workflows/daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
- run: AUTOBAHN=1 ./ci/bench.sh
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
- run: AUTOBAHN=1 ./ci/test.sh
Expand All @@ -34,7 +34,7 @@ jobs:
- uses: actions/checkout@v4
with:
ref: dev
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
- run: AUTOBAHN=1 ./ci/bench.sh
Expand All @@ -44,11 +44,11 @@ jobs:
- uses: actions/checkout@v4
with:
ref: dev
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
- run: AUTOBAHN=1 ./ci/test.sh
- uses: actions/upload-artifact@v3
with:
name: coverage.html
name: coverage-dev.html
path: ./ci/out/coverage.html
37 changes: 37 additions & 0 deletions accept_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"net/http/httptest"
"strings"
"sync"
"testing"

"nhooyr.io/websocket/internal/test/assert"
Expand Down Expand Up @@ -142,6 +143,42 @@ func TestAccept(t *testing.T) {
_, err := Accept(w, r, nil)
assert.Contains(t, err, `failed to hijack connection`)
})
t.Run("closeRace", func(t *testing.T) {
t.Parallel()

server, _ := net.Pipe()

rw := bufio.NewReadWriter(bufio.NewReader(server), bufio.NewWriter(server))
newResponseWriter := func() http.ResponseWriter {
return mockHijacker{
ResponseWriter: httptest.NewRecorder(),
hijack: func() (net.Conn, *bufio.ReadWriter, error) {
return server, rw, nil
},
}
}
w := newResponseWriter()

r := httptest.NewRequest("GET", "/", nil)
r.Header.Set("Connection", "Upgrade")
r.Header.Set("Upgrade", "websocket")
r.Header.Set("Sec-WebSocket-Version", "13")
r.Header.Set("Sec-WebSocket-Key", xrand.Base64(16))

c, err := Accept(w, r, nil)
wg := &sync.WaitGroup{}
wg.Add(2)
go func() {
c.Close(StatusInternalError, "the sky is falling")
wg.Done()
}()
go func() {
c.CloseNow()
wg.Done()
}()
wg.Wait()
assert.Success(t, err)
})
}

func Test_verifyClientHandshake(t *testing.T) {
Expand Down
15 changes: 13 additions & 2 deletions ci/bench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@
set -eu
cd -- "$(dirname "$0")/.."

go test --run=^$ --bench=. --benchmem --memprofile ci/out/prof.mem --cpuprofile ci/out/prof.cpu -o ci/out/websocket.test "$@" .
go test --run=^$ --bench=. --benchmem "$@" ./...
# For profiling add: --memprofile ci/out/prof.mem --cpuprofile ci/out/prof.cpu -o ci/out/websocket.test
(
cd ./internal/thirdparty
go test --run=^$ --bench=. --benchmem --memprofile ../../ci/out/prof-thirdparty.mem --cpuprofile ../../ci/out/prof-thirdparty.cpu -o ../../ci/out/thirdparty.test "$@" .
go test --run=^$ --bench=. --benchmem "$@" .

GOARCH=arm64 go test -c -o ../../ci/out/thirdparty-arm64.test "$@" .
if [ "$#" -eq 0 ]; then
if [ "${CI-}" ]; then
sudo apt-get update
sudo apt-get install -y qemu-user-static
ln -s /usr/bin/qemu-aarch64-static /usr/local/bin/qemu-aarch64
fi
qemu-aarch64 ../../ci/out/thirdparty-arm64.test --test.run=^$ --test.bench=Benchmark_mask --test.benchmem
fi
)
4 changes: 4 additions & 0 deletions ci/fmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ npx [email protected] \
$(git ls-files "*.yml" "*.md" "*.js" "*.css" "*.html")

go run golang.org/x/tools/cmd/stringer@latest -type=opcode,MessageType,StatusCode -output=stringer.go

if [ "${CI-}" ]; then
git diff --exit-code
fi
13 changes: 13 additions & 0 deletions ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ cd -- "$(dirname "$0")/.."
go test "$@" ./...
)

(
GOARCH=arm64 go test -c -o ./ci/out/websocket-arm64.test "$@" .
if [ "$#" -eq 0 ]; then
if [ "${CI-}" ]; then
sudo apt-get update
sudo apt-get install -y qemu-user-static
ln -s /usr/bin/qemu-aarch64-static /usr/local/bin/qemu-aarch64
fi
qemu-aarch64 ./ci/out/websocket-arm64.test -test.run=TestMask
fi
)


go install github.com/agnivade/wasmbrowsertest@latest
go test --race --bench=. --timeout=1h --covermode=atomic --coverprofile=ci/out/coverage.prof --coverpkg=./... "$@" ./...
sed -i.bak '/stringer\.go/d' ci/out/coverage.prof
Expand Down
Loading

0 comments on commit bd07a64

Please sign in to comment.