From b452a8164ee567ec405f493e037e30c9f9e4aebd Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Wed, 19 Apr 2023 11:29:10 -0400 Subject: [PATCH] all: fix non-gopls short tests on js/wasm and update for wasip1/wasm testenv.HasExec should not assume that "js" and "ios" are the only platforms that can't exec. Instead of hard-coding a list of GOOS, hard-code only the ones known to work and probe the remainder by trying to re-exec the test binary. Similarly, in testenv_notunix, negate the list of unix platforms instead of hard-coding the non-unix ones. Add missing calls to testenv functions were needed. For golang/go#58141. Updates golang/go#59718. Change-Id: I0114e0bfb6d091e84b325d7f9bb0896da22482be Reviewed-on: https://go-review.googlesource.com/c/tools/+/486315 Reviewed-by: Johan Brandhorst-Satzkorn Run-TryBot: Bryan Mills Commit-Queue: Bryan Mills Reviewed-by: Dmitri Shuralyov Auto-Submit: Bryan Mills TryBot-Result: Gopher Robot --- internal/jsonrpc2/serve_test.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/jsonrpc2/serve_test.go b/internal/jsonrpc2/serve_test.go index 364b1e9..6a8ca6f 100644 --- a/internal/jsonrpc2/serve_test.go +++ b/internal/jsonrpc2/serve_test.go @@ -14,9 +14,11 @@ import ( "github.com/modelcontextprotocol/go-sdk/internal/jsonrpc2" "golang.org/x/tools/internal/stack/stacktest" + "golang.org/x/tools/internal/testenv" ) func TestIdleTimeout(t *testing.T) { + testenv.NeedsLocalhostNet(t) stacktest.NoLeak(t) // Use a panicking time.AfterFunc instead of context.WithTimeout so that we @@ -161,19 +163,20 @@ func TestServe(t *testing.T) { tests := []struct { name string - factory func(context.Context) (jsonrpc2.Listener, error) + factory func(context.Context, testing.TB) (jsonrpc2.Listener, error) }{ - {"tcp", func(ctx context.Context) (jsonrpc2.Listener, error) { + {"tcp", func(ctx context.Context, t testing.TB) (jsonrpc2.Listener, error) { + testenv.NeedsLocalhostNet(t) return jsonrpc2.NetListener(ctx, "tcp", "localhost:0", jsonrpc2.NetListenOptions{}) }}, - {"pipe", func(ctx context.Context) (jsonrpc2.Listener, error) { + {"pipe", func(ctx context.Context, t testing.TB) (jsonrpc2.Listener, error) { return jsonrpc2.NetPipeListener(ctx) }}, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - fake, err := test.factory(ctx) + fake, err := test.factory(ctx, t) if err != nil { t.Fatal(err) }