From b2efd4d155d2908456f148c650480be8135e1e9c Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Tue, 1 Mar 2022 15:17:42 -0500 Subject: [PATCH] internal/jsonrpc2_v2: eliminate most arbitrary timeouts in tests For golang/go#46047 For golang/go#49387 For golang/go#46520 Change-Id: Ib72863a024d74f45c70a6cb53482cb606510f7e4 Reviewed-on: https://go-review.googlesource.com/c/tools/+/388598 Run-TryBot: Bryan Mills Reviewed-by: Ian Cottrell TryBot-Result: Gopher Robot gopls-CI: kokoro Auto-Submit: Bryan Mills --- internal/jsonrpc2_v2/jsonrpc2_test.go | 5 ----- internal/jsonrpc2_v2/serve_test.go | 5 ++--- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/internal/jsonrpc2_v2/jsonrpc2_test.go b/internal/jsonrpc2_v2/jsonrpc2_test.go index c63a6a982b..b2fa4963b7 100644 --- a/internal/jsonrpc2_v2/jsonrpc2_test.go +++ b/internal/jsonrpc2_v2/jsonrpc2_test.go @@ -11,7 +11,6 @@ import ( "path" "reflect" "testing" - "time" "golang.org/x/tools/internal/event/export/eventtest" jsonrpc2 "golang.org/x/tools/internal/jsonrpc2_v2" @@ -370,8 +369,6 @@ func (h *handler) Handle(ctx context.Context, req *jsonrpc2.Request) (interface{ return true, nil case <-ctx.Done(): return nil, ctx.Err() - case <-time.After(time.Second): - return nil, fmt.Errorf("wait for %q timed out", name) } case "fork": var name string @@ -385,8 +382,6 @@ func (h *handler) Handle(ctx context.Context, req *jsonrpc2.Request) (interface{ h.conn.Respond(req.ID, true, nil) case <-ctx.Done(): h.conn.Respond(req.ID, nil, ctx.Err()) - case <-time.After(time.Second): - h.conn.Respond(req.ID, nil, fmt.Errorf("wait for %q timed out", name)) } }() return nil, jsonrpc2.ErrAsyncResponse diff --git a/internal/jsonrpc2_v2/serve_test.go b/internal/jsonrpc2_v2/serve_test.go index 9ca513361b..f0c27a8be5 100644 --- a/internal/jsonrpc2_v2/serve_test.go +++ b/internal/jsonrpc2_v2/serve_test.go @@ -28,6 +28,7 @@ func TestIdleTimeout(t *testing.T) { panic("TestIdleTimeout deadlocked") }) defer timer.Stop() + ctx := context.Background() try := func(d time.Duration) (longEnough bool) { @@ -149,8 +150,7 @@ func (fakeHandler) Handle(ctx context.Context, req *jsonrpc2.Request) (interface func TestServe(t *testing.T) { stacktest.NoLeak(t) - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() + ctx := context.Background() tests := []struct { name string @@ -187,7 +187,6 @@ func TestServe(t *testing.T) { } func newFake(t *testing.T, ctx context.Context, l jsonrpc2.Listener) (*jsonrpc2.Connection, func(), error) { - l = jsonrpc2.NewIdleListener(100*time.Millisecond, l) server, err := jsonrpc2.Serve(ctx, l, jsonrpc2.ConnectionOptions{ Handler: fakeHandler{}, })