good morning!!!!

Skip to content
Snippets Groups Projects
Unverified Commit 6975801d authored by Anmol Sethi's avatar Anmol Sethi
Browse files

Fix race in tests

parent d0926864
No related branches found
No related tags found
No related merge requests found
......@@ -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)
}
......
......@@ -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()
......
......@@ -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{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment