diff --git a/assert_test.go b/assert_test.go index 22814e3bd71444c1391c2dc9b0f84d9f9196e4e1..a51b2c3da05fcec391120c08aeab219648cc0be6 100644 --- a/assert_test.go +++ b/assert_test.go @@ -28,7 +28,7 @@ func echoJSON(t *testing.T, c *websocket.Conn, n int) { slog.Helper() s := randString(t, n) - writeJSON(t, c, s) + go writeJSON(t, c, s) readJSON(t, c, s) } diff --git a/autobahn_test.go b/autobahn_test.go index 71d22be7adf89be8c529dbd22f6f2985f9549b92..d730cf4a70ccb38963ea842695d70e0bc3e2c6db 100644 --- a/autobahn_test.go +++ b/autobahn_test.go @@ -8,6 +8,7 @@ import ( "fmt" "io/ioutil" "net" + "os" "os/exec" "strconv" "strings" @@ -36,6 +37,10 @@ var autobahnCases = []string{"*"} func TestAutobahn(t *testing.T) { t.Parallel() + if os.Getenv("AUTOBAHN_TEST") == "" { + t.SkipNow() + } + ctx, cancel := context.WithTimeout(context.Background(), time.Minute*15) defer cancel() diff --git a/conn_test.go b/conn_test.go index aceac3fdf7a10d867a16e05a9535b5b7ee941a57..f1361adccc16fef48ffa97ff93061c9ba3c801a6 100644 --- a/conn_test.go +++ b/conn_test.go @@ -39,7 +39,7 @@ func TestConn(t *testing.T) { for i := 0; i < 1; i++ { t.Run("", func(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), time.Second) + ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() c1, c2 := websocketPipe(t) @@ -49,6 +49,7 @@ func TestConn(t *testing.T) { assertCloseStatus(t, websocket.StatusNormalClosure, err) }) defer wait() + defer cancel() c2.SetReadLimit(1 << 30) @@ -63,12 +64,6 @@ func TestConn(t *testing.T) { }) } -type writerFunc func(p []byte) (int, error) - -func (f writerFunc) Write(p []byte) (int, error) { - return f(p) -} - // echoLoop echos every msg received from c until an error // occurs or the context expires. // The read limit is set to 1 << 30. @@ -104,7 +99,7 @@ func echoLoop(ctx context.Context, c *websocket.Conn) error { } } -func randBool(t testing.TB) bool { +func randBool(t testing.TB) bool { return randInt(t, 2) == 1 } @@ -117,7 +112,7 @@ func randInt(t testing.TB, max int) int { type testHijacker struct { *httptest.ResponseRecorder serverConn net.Conn - hijacked chan struct{} + hijacked chan struct{} } var _ http.Hijacker = testHijacker{} @@ -154,7 +149,7 @@ type testTransport struct { h http.HandlerFunc } -func (t testTransport) RoundTrip(r *http.Request) (*http.Response, error) { +func (t testTransport) RoundTrip(r *http.Request) (*http.Response, error) { clientConn, serverConn := net.Pipe() hj := testHijacker{