From 382864a00f3ff9ce61d633899bc5e64f6e58f904 Mon Sep 17 00:00:00 2001
From: Anmol Sethi <hi@nhooyr.io>
Date: Wed, 27 Sep 2023 22:27:18 -0700
Subject: [PATCH] wip

---
 accept.go                    |  1 +
 accept_test.go               |  1 +
 autobahn_test.go             | 45 ++++++++++++++++++++++++++++--------
 close.go                     |  1 +
 close_test.go                |  1 +
 compress.go                  |  1 +
 compress_test.go             |  1 +
 conn.go                      |  1 +
 conn_test.go                 |  1 +
 dial.go                      |  1 +
 dial_test.go                 |  1 +
 doc.go                       | 11 +++++----
 export_test.go               |  1 +
 frame_test.go                |  1 +
 internal/test/wstest/echo.go |  2 +-
 internal/test/wstest/pipe.go |  1 +
 internal/wsjs/wsjs_js.go     |  1 +
 make.sh                      | 17 ++++++++++++++
 read.go                      |  1 +
 write.go                     |  1 +
 20 files changed, 75 insertions(+), 16 deletions(-)
 create mode 100755 make.sh

diff --git a/accept.go b/accept.go
index 542b61e..d918aab 100644
--- a/accept.go
+++ b/accept.go
@@ -1,3 +1,4 @@
+//go:build !js
 // +build !js
 
 package websocket
diff --git a/accept_test.go b/accept_test.go
index 67ece25..ae17c0b 100644
--- a/accept_test.go
+++ b/accept_test.go
@@ -1,3 +1,4 @@
+//go:build !js
 // +build !js
 
 package websocket
diff --git a/autobahn_test.go b/autobahn_test.go
index 1c8c417..8e569d0 100644
--- a/autobahn_test.go
+++ b/autobahn_test.go
@@ -1,3 +1,4 @@
+//go:build !js
 // +build !js
 
 package websocket_test
@@ -33,6 +34,12 @@ var excludedAutobahnCases = []string{
 
 var autobahnCases = []string{"*"}
 
+// Used to run individual test cases. autobahnCases runs only those cases matched
+// and not excluded by excludedAutobahnCases. Adding cases here means excludedAutobahnCases
+// is niled.
+// TODO:
+var forceAutobahnCases = []string{}
+
 func TestAutobahn(t *testing.T) {
 	t.Parallel()
 
@@ -43,11 +50,11 @@ func TestAutobahn(t *testing.T) {
 	if os.Getenv("AUTOBAHN") == "fast" {
 		// These are the slow tests.
 		excludedAutobahnCases = append(excludedAutobahnCases,
-			"9.*", "13.*", "12.*",
+			"9.*", "12.*", "13.*",
 		)
 	}
 
-	ctx, cancel := context.WithTimeout(context.Background(), time.Minute*15)
+	ctx, cancel := context.WithTimeout(context.Background(), time.Hour)
 	defer cancel()
 
 	wstestURL, closeFn, err := wstestClientServer(ctx)
@@ -105,12 +112,17 @@ func wstestClientServer(ctx context.Context) (url string, closeFn func(), err er
 	if err != nil {
 		return "", nil, err
 	}
+	_, serverPort, err := net.SplitHostPort(serverAddr)
+	if err != nil {
+		return "", nil, err
+	}
 
 	url = "ws://" + serverAddr
+	const outDir = "ci/out/wstestClientReports"
 
 	specFile, err := tempJSONFile(map[string]interface{}{
 		"url":           url,
-		"outdir":        "ci/out/wstestClientReports",
+		"outdir":        outDir,
 		"cases":         autobahnCases,
 		"exclude-cases": excludedAutobahnCases,
 	})
@@ -118,32 +130,45 @@ func wstestClientServer(ctx context.Context) (url string, closeFn func(), err er
 		return "", nil, fmt.Errorf("failed to write spec: %w", err)
 	}
 
-	ctx, cancel := context.WithTimeout(context.Background(), time.Minute*15)
+	ctx, cancel := context.WithTimeout(context.Background(), time.Hour)
 	defer func() {
 		if err != nil {
 			cancel()
 		}
 	}()
 
+	wd, err := os.Getwd()
+	if err != nil {
+		return "", nil, err
+	}
+
 	var args []string
-	args = append(args, "run", "-it", "--rm",
-    -v "${PWD}/config:/specFile", \
-    -v "${PWD}/reports:/reports", \
-    "-p=9001:9001", \
-    "--name=fuzzingserver", \
-    "crossbario/autobahn-testsuite",
+	args = append(args, "run", "-i", "--rm",
+		"-v", fmt.Sprintf("%s:%[1]s", specFile),
+		"-v", fmt.Sprintf("%s/ci:/ci", wd),
+		fmt.Sprintf("-p=%s:%s", serverAddr, serverPort),
+		"--name=fuzzingserver",
+		"crossbario/autobahn-testsuite",
+	)
 	args = append(args, "wstest", "--mode", "fuzzingserver", "--spec", specFile,
 		// 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",
 	)
+	fmt.Println(strings.Join(args, " "))
+	// TODO: pull image in advance
 	wstest := exec.CommandContext(ctx, "docker", args...)
+	// TODO: log to *testing.T
+	wstest.Stdout = os.Stdout
+	wstest.Stderr = os.Stderr
 	err = wstest.Start()
 	if err != nil {
 		return "", nil, fmt.Errorf("failed to start wstest: %w", err)
 	}
 
+	// TODO: kill
 	return url, func() {
+		// TODO: super kill
 		wstest.Process.Kill()
 	}, nil
 }
diff --git a/close.go b/close.go
index d76dc2f..eab49a8 100644
--- a/close.go
+++ b/close.go
@@ -1,3 +1,4 @@
+//go:build !js
 // +build !js
 
 package websocket
diff --git a/close_test.go b/close_test.go
index 00a48d9..6bf3c25 100644
--- a/close_test.go
+++ b/close_test.go
@@ -1,3 +1,4 @@
+//go:build !js
 // +build !js
 
 package websocket
diff --git a/compress.go b/compress.go
index f49d9e5..6873447 100644
--- a/compress.go
+++ b/compress.go
@@ -1,3 +1,4 @@
+//go:build !js
 // +build !js
 
 package websocket
diff --git a/compress_test.go b/compress_test.go
index 2c4c896..7b0e3a6 100644
--- a/compress_test.go
+++ b/compress_test.go
@@ -1,3 +1,4 @@
+//go:build !js
 // +build !js
 
 package websocket
diff --git a/conn.go b/conn.go
index beb26ce..25b5a20 100644
--- a/conn.go
+++ b/conn.go
@@ -1,3 +1,4 @@
+//go:build !js
 // +build !js
 
 package websocket
diff --git a/conn_test.go b/conn_test.go
index 0fbd174..19961d1 100644
--- a/conn_test.go
+++ b/conn_test.go
@@ -1,3 +1,4 @@
+//go:build !js
 // +build !js
 
 package websocket_test
diff --git a/dial.go b/dial.go
index a79b55e..7e77d6e 100644
--- a/dial.go
+++ b/dial.go
@@ -1,3 +1,4 @@
+//go:build !js
 // +build !js
 
 package websocket
diff --git a/dial_test.go b/dial_test.go
index 28c255c..e5f8ab3 100644
--- a/dial_test.go
+++ b/dial_test.go
@@ -1,3 +1,4 @@
+//go:build !js
 // +build !js
 
 package websocket
diff --git a/doc.go b/doc.go
index efa920e..a2b873c 100644
--- a/doc.go
+++ b/doc.go
@@ -1,3 +1,4 @@
+//go:build !js
 // +build !js
 
 // Package websocket implements the RFC 6455 WebSocket protocol.
@@ -16,7 +17,7 @@
 //
 // More documentation at https://nhooyr.io/websocket.
 //
-// Wasm
+// # Wasm
 //
 // The client side supports compiling to Wasm.
 // It wraps the WebSocket browser API.
@@ -25,8 +26,8 @@
 //
 // Some important caveats to be aware of:
 //
-//  - Accept always errors out
-//  - Conn.Ping is no-op
-//  - HTTPClient, HTTPHeader and CompressionMode in DialOptions are no-op
-//  - *http.Response from Dial is &http.Response{} with a 101 status code on success
+//   - Accept always errors out
+//   - Conn.Ping is no-op
+//   - HTTPClient, HTTPHeader and CompressionMode in DialOptions are no-op
+//   - *http.Response from Dial is &http.Response{} with a 101 status code on success
 package websocket // import "nhooyr.io/websocket"
diff --git a/export_test.go b/export_test.go
index 88b82c9..d618a15 100644
--- a/export_test.go
+++ b/export_test.go
@@ -1,3 +1,4 @@
+//go:build !js
 // +build !js
 
 package websocket
diff --git a/frame_test.go b/frame_test.go
index 7682624..93ad8b5 100644
--- a/frame_test.go
+++ b/frame_test.go
@@ -1,3 +1,4 @@
+//go:build !js
 // +build !js
 
 package websocket
diff --git a/internal/test/wstest/echo.go b/internal/test/wstest/echo.go
index 8f4e47c..0938a13 100644
--- a/internal/test/wstest/echo.go
+++ b/internal/test/wstest/echo.go
@@ -21,7 +21,7 @@ func EchoLoop(ctx context.Context, c *websocket.Conn) error {
 
 	c.SetReadLimit(1 << 30)
 
-	ctx, cancel := context.WithTimeout(ctx, time.Minute)
+	ctx, cancel := context.WithTimeout(ctx, time.Minute*5)
 	defer cancel()
 
 	b := make([]byte, 32<<10)
diff --git a/internal/test/wstest/pipe.go b/internal/test/wstest/pipe.go
index f3d4c51..8e1deb4 100644
--- a/internal/test/wstest/pipe.go
+++ b/internal/test/wstest/pipe.go
@@ -1,3 +1,4 @@
+//go:build !js
 // +build !js
 
 package wstest
diff --git a/internal/wsjs/wsjs_js.go b/internal/wsjs/wsjs_js.go
index 26ffb45..88e8f43 100644
--- a/internal/wsjs/wsjs_js.go
+++ b/internal/wsjs/wsjs_js.go
@@ -1,3 +1,4 @@
+//go:build js
 // +build js
 
 // Package wsjs implements typed access to the browser javascript WebSocket API.
diff --git a/make.sh b/make.sh
new file mode 100755
index 0000000..6fe7e07
--- /dev/null
+++ b/make.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+set -eu
+
+cd "$(dirname "$0")"
+
+fmt() {
+	go mod tidy
+	gofmt -s -w .
+	goimports -w "-local=$(go list -m)" .
+}
+
+if ! command -v wasmbrowsertest >/dev/null; then
+	go install github.com/agnivade/wasmbrowsertest@latest
+fi
+
+fmt
+#AUTOBAHN=1 go test -race --timeout=1h ./... "$@"
diff --git a/read.go b/read.go
index c4234f2..19727fd 100644
--- a/read.go
+++ b/read.go
@@ -1,3 +1,4 @@
+//go:build !js
 // +build !js
 
 package websocket
diff --git a/write.go b/write.go
index 58bfdf9..7921eac 100644
--- a/write.go
+++ b/write.go
@@ -1,3 +1,4 @@
+//go:build !js
 // +build !js
 
 package websocket
-- 
GitLab