Skip to content

Commit 6975801

Browse files
committed
Fix race in tests
1 parent d092686 commit 6975801

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

assert_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func echoJSON(t *testing.T, c *websocket.Conn, n int) {
2828
slog.Helper()
2929

3030
s := randString(t, n)
31-
writeJSON(t, c, s)
31+
go writeJSON(t, c, s)
3232
readJSON(t, c, s)
3333
}
3434

autobahn_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"io/ioutil"
1010
"net"
11+
"os"
1112
"os/exec"
1213
"strconv"
1314
"strings"
@@ -36,6 +37,10 @@ var autobahnCases = []string{"*"}
3637
func TestAutobahn(t *testing.T) {
3738
t.Parallel()
3839

40+
if os.Getenv("AUTOBAHN_TEST") == "" {
41+
t.SkipNow()
42+
}
43+
3944
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*15)
4045
defer cancel()
4146

conn_test.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestConn(t *testing.T) {
3939

4040
for i := 0; i < 1; i++ {
4141
t.Run("", func(t *testing.T) {
42-
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
42+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
4343
defer cancel()
4444

4545
c1, c2 := websocketPipe(t)
@@ -49,6 +49,7 @@ func TestConn(t *testing.T) {
4949
assertCloseStatus(t, websocket.StatusNormalClosure, err)
5050
})
5151
defer wait()
52+
defer cancel()
5253

5354
c2.SetReadLimit(1 << 30)
5455

@@ -63,12 +64,6 @@ func TestConn(t *testing.T) {
6364
})
6465
}
6566

66-
type writerFunc func(p []byte) (int, error)
67-
68-
func (f writerFunc) Write(p []byte) (int, error) {
69-
return f(p)
70-
}
71-
7267
// echoLoop echos every msg received from c until an error
7368
// occurs or the context expires.
7469
// The read limit is set to 1 << 30.
@@ -104,7 +99,7 @@ func echoLoop(ctx context.Context, c *websocket.Conn) error {
10499
}
105100
}
106101

107-
func randBool(t testing.TB) bool {
102+
func randBool(t testing.TB) bool {
108103
return randInt(t, 2) == 1
109104
}
110105

@@ -117,7 +112,7 @@ func randInt(t testing.TB, max int) int {
117112
type testHijacker struct {
118113
*httptest.ResponseRecorder
119114
serverConn net.Conn
120-
hijacked chan struct{}
115+
hijacked chan struct{}
121116
}
122117

123118
var _ http.Hijacker = testHijacker{}
@@ -154,7 +149,7 @@ type testTransport struct {
154149
h http.HandlerFunc
155150
}
156151

157-
func (t testTransport) RoundTrip(r *http.Request) (*http.Response, error) {
152+
func (t testTransport) RoundTrip(r *http.Request) (*http.Response, error) {
158153
clientConn, serverConn := net.Pipe()
159154

160155
hj := testHijacker{

0 commit comments

Comments
 (0)