- Notifications
You must be signed in to change notification settings - Fork329
Rewrite with compression support#163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
56 commits Select commitHold shift + click to select a range
8604dee
Increase TestWASM timeout
nhooyre55ac18
Document compression API
nhooyre142e08
Improve compression docs
nhooyr53c1aea
Implement compression extension negotiation
nhooyr2cf6c28
Implement compression writer and reader pooling
nhooyra01afea
Support x-webkit-deflate-frame extension for Safari
nhooyr531d4fa
Improve general compression API and write docs
nhooyrd0a8049
Rewrite core
nhooyrdd107dd
Update CI
nhooyr6c6b8e9
Cleanup wspb and wsjson
nhooyr6b782a3
Run make fmt
nhooyr989ba2f
Change websocket to WebSocket in docs/errors
nhooyr9f15963
Simplify dial.go
nhooyr120911b
Remove use of math/rand.Init
nhooyr7ad1514
Update README.md comparison
nhooyr746140b
Further improve README
nhooyr43cb01e
Refactor read.go/write.go
nhooyre8dfe27
Make CI pass
nhooyrf6137f3
Add minor improvements
nhooyr6f6fa43
Refactor autobahn
nhooyr8c87970
Add slidingWindowReader
nhooyraaf4b45
Up test coverage of accept.go to 100%
nhooyr6b76536
Up dial coverage to 100%
nhooyr0f115ed
Add Go 1.12 support
nhooyrb6b56b7
Both modes seem to work :)
nhooyr9e32354
Fix randString method in tests
nhooyr78da35e
Get test with multiple messages working
nhooyrd092686
Autobahn tests fully pass :)
nhooyr6975801
Fix race in tests
nhooyrbbaf469
Fix test step
nhooyrfaadcc9
Simplify tests
nhooyr3f2589f
Remove quite a bit of slog
nhooyrb53f306
Get Wasm tests working
nhooyr69ff675
More tests and fixes
nhooyr085e671
Get coverage to 85%
nhooyr51769b3
Add wspb test
nhooyr670be05
Merge in handshake improvements from master
nhooyr988b8f2
Merge remote-tracking branch 'origin/master' into compress
nhooyr3a526d8
Fix bug in closeHandshake
nhooyr999b812
Fix race in msgReader
nhooyr4b84d25
Fix a race with c.closed
nhooyr85f249d
Up timeouts
nhooyr6b38ebb
Test fixes
nhooyr6770421
Fix goroutine leak from deadlock when closing
nhooyrc752365
Make flateThreshold work
nhooyr0ea9466
Cleanup writeMu and flateThreshold
nhooyrb33d48c
Minor cleanup
nhooyr9c5bfab
Simplifications of conn_test.go
nhooyr3673c2c
Use basic test assertions
nhooyrc5b0a00
Fix badPing test duration
nhooyr1c7c14e
Pool sliding windows
nhooyr503b469
Simplify sliding window API
nhooyrdff4af3
Add conn benchmark
nhooyr2377cca
Switch to klauspost/compress
nhooyrd57b253
Report how efficient compression is in BenchmarkConn
nhooyr1bc100d
Update docs and random little issues
nhooyrFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Rewrite core
Too many improvements and changes to list.Will include a detailed changelog for release.
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commitd0a80496108cf7cdd4e20c24e4689cd5934b5b89
There are no files selected for viewing
63 changes: 36 additions & 27 deletionsaccept.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletionsassert_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
252 changes: 252 additions & 0 deletionsautobahn_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,252 @@ | ||
package websocket_test | ||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net" | ||
"net/http" | ||
"net/http/httptest" | ||
"nhooyr.io/websocket" | ||
"os" | ||
"os/exec" | ||
"strconv" | ||
"strings" | ||
"testing" | ||
"time" | ||
) | ||
func TestAutobahn(t *testing.T) { | ||
// This test contains the old autobahn test suite tests that use the | ||
// python binary. The approach is clunky and slow so new tests | ||
// have been written in pure Go in websocket_test.go. | ||
// These have been kept for correctness purposes and are occasionally ran. | ||
if os.Getenv("AUTOBAHN") == "" { | ||
t.Skip("Set $AUTOBAHN to run tests against the autobahn test suite") | ||
} | ||
t.Run("server", testServerAutobahnPython) | ||
t.Run("client", testClientAutobahnPython) | ||
} | ||
// https://github.com/crossbario/autobahn-python/tree/master/wstest | ||
func testServerAutobahnPython(t *testing.T) { | ||
t.Parallel() | ||
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
c, err := websocket.Accept(w, r, &websocket.AcceptOptions{ | ||
Subprotocols: []string{"echo"}, | ||
}) | ||
if err != nil { | ||
t.Logf("server handshake failed: %+v", err) | ||
return | ||
} | ||
echoLoop(r.Context(), c) | ||
})) | ||
defer s.Close() | ||
spec := map[string]interface{}{ | ||
"outdir": "ci/out/wstestServerReports", | ||
"servers": []interface{}{ | ||
map[string]interface{}{ | ||
"agent": "main", | ||
"url": strings.Replace(s.URL, "http", "ws", 1), | ||
}, | ||
}, | ||
"cases": []string{"*"}, | ||
// We skip the UTF-8 handling tests as there isn't any reason to reject invalid UTF-8, just | ||
// more performance overhead. 7.5.1 is the same. | ||
"exclude-cases": []string{"6.*", "7.5.1"}, | ||
} | ||
specFile, err := ioutil.TempFile("", "websocketFuzzingClient.json") | ||
if err != nil { | ||
t.Fatalf("failed to create temp file for fuzzingclient.json: %v", err) | ||
} | ||
defer specFile.Close() | ||
e := json.NewEncoder(specFile) | ||
e.SetIndent("", "\t") | ||
err = e.Encode(spec) | ||
if err != nil { | ||
t.Fatalf("failed to write spec: %v", err) | ||
} | ||
err = specFile.Close() | ||
if err != nil { | ||
t.Fatalf("failed to close file: %v", err) | ||
} | ||
ctx := context.Background() | ||
ctx, cancel := context.WithTimeout(ctx, time.Minute*10) | ||
defer cancel() | ||
args := []string{"--mode", "fuzzingclient", "--spec", specFile.Name()} | ||
wstest := exec.CommandContext(ctx, "wstest", args...) | ||
out, err := wstest.CombinedOutput() | ||
if err != nil { | ||
t.Fatalf("failed to run wstest: %v\nout:\n%s", err, out) | ||
} | ||
checkWSTestIndex(t, "./ci/out/wstestServerReports/index.json") | ||
} | ||
func unusedListenAddr() (string, error) { | ||
l, err := net.Listen("tcp", "localhost:0") | ||
if err != nil { | ||
return "", err | ||
} | ||
l.Close() | ||
return l.Addr().String(), nil | ||
} | ||
// https://github.com/crossbario/autobahn-python/blob/master/wstest/testee_client_aio.py | ||
func testClientAutobahnPython(t *testing.T) { | ||
t.Parallel() | ||
if os.Getenv("AUTOBAHN_PYTHON") == "" { | ||
t.Skip("Set $AUTOBAHN_PYTHON to test against the python autobahn test suite") | ||
} | ||
serverAddr, err := unusedListenAddr() | ||
if err != nil { | ||
t.Fatalf("failed to get unused listen addr for wstest: %v", err) | ||
} | ||
wsServerURL := "ws://" + serverAddr | ||
spec := map[string]interface{}{ | ||
"url": wsServerURL, | ||
"outdir": "ci/out/wstestClientReports", | ||
"cases": []string{"*"}, | ||
// See TestAutobahnServer for the reasons why we exclude these. | ||
"exclude-cases": []string{"6.*", "7.5.1"}, | ||
} | ||
specFile, err := ioutil.TempFile("", "websocketFuzzingServer.json") | ||
if err != nil { | ||
t.Fatalf("failed to create temp file for fuzzingserver.json: %v", err) | ||
} | ||
defer specFile.Close() | ||
e := json.NewEncoder(specFile) | ||
e.SetIndent("", "\t") | ||
err = e.Encode(spec) | ||
if err != nil { | ||
t.Fatalf("failed to write spec: %v", err) | ||
} | ||
err = specFile.Close() | ||
if err != nil { | ||
t.Fatalf("failed to close file: %v", err) | ||
} | ||
ctx := context.Background() | ||
ctx, cancel := context.WithTimeout(ctx, time.Minute*10) | ||
defer cancel() | ||
args := []string{"--mode", "fuzzingserver", "--spec", specFile.Name(), | ||
// Disables some server that runs as part of fuzzingserver mode. | ||
// See https://github.com/crossbario/autobahn-testsuite/blob/058db3a36b7c3a1edf68c282307c6b899ca4857f/autobahntestsuite/autobahntestsuite/wstest.py#L124 | ||
"--webport=0", | ||
} | ||
wstest := exec.CommandContext(ctx, "wstest", args...) | ||
err = wstest.Start() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer func() { | ||
err := wstest.Process.Kill() | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
}() | ||
// Let it come up. | ||
time.Sleep(time.Second * 5) | ||
var cases int | ||
func() { | ||
c, _, err := websocket.Dial(ctx, wsServerURL+"/getCaseCount", nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer c.Close(websocket.StatusInternalError, "") | ||
_, r, err := c.Reader(ctx) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
b, err := ioutil.ReadAll(r) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
cases, err = strconv.Atoi(string(b)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
c.Close(websocket.StatusNormalClosure, "") | ||
}() | ||
for i := 1; i <= cases; i++ { | ||
func() { | ||
ctx, cancel := context.WithTimeout(ctx, time.Second*45) | ||
defer cancel() | ||
c, _, err := websocket.Dial(ctx, fmt.Sprintf(wsServerURL+"/runCase?case=%v&agent=main", i), nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
echoLoop(ctx, c) | ||
}() | ||
} | ||
c, _, err := websocket.Dial(ctx, fmt.Sprintf(wsServerURL+"/updateReports?agent=main"), nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
c.Close(websocket.StatusNormalClosure, "") | ||
checkWSTestIndex(t, "./ci/out/wstestClientReports/index.json") | ||
} | ||
func checkWSTestIndex(t *testing.T, path string) { | ||
wstestOut, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
t.Fatalf("failed to read index.json: %v", err) | ||
} | ||
var indexJSON map[string]map[string]struct { | ||
Behavior string `json:"behavior"` | ||
BehaviorClose string `json:"behaviorClose"` | ||
} | ||
err = json.Unmarshal(wstestOut, &indexJSON) | ||
if err != nil { | ||
t.Fatalf("failed to unmarshal index.json: %v", err) | ||
} | ||
var failed bool | ||
for _, tests := range indexJSON { | ||
for test, result := range tests { | ||
switch result.Behavior { | ||
case "OK", "NON-STRICT", "INFORMATIONAL": | ||
default: | ||
failed = true | ||
t.Errorf("test %v failed", test) | ||
} | ||
switch result.BehaviorClose { | ||
case "OK", "INFORMATIONAL": | ||
default: | ||
failed = true | ||
t.Errorf("bad close behaviour for test %v", test) | ||
} | ||
} | ||
} | ||
if failed { | ||
path = strings.Replace(path, ".json", ".html", 1) | ||
if os.Getenv("CI") == "" { | ||
t.Errorf("wstest found failure, see %q (output as an artifact in CI)", path) | ||
} | ||
} | ||
} |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.