Skip to content

Commit b2efd4d

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
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 <[email protected]> Reviewed-by: Ian Cottrell <[email protected]> TryBot-Result: Gopher Robot <[email protected]> gopls-CI: kokoro <[email protected]> Auto-Submit: Bryan Mills <[email protected]>
1 parent 371ef16 commit b2efd4d

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

internal/jsonrpc2_v2/jsonrpc2_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"path"
1212
"reflect"
1313
"testing"
14-
"time"
1514

1615
"golang.org/x/tools/internal/event/export/eventtest"
1716
jsonrpc2 "golang.org/x/tools/internal/jsonrpc2_v2"
@@ -370,8 +369,6 @@ func (h *handler) Handle(ctx context.Context, req *jsonrpc2.Request) (interface{
370369
return true, nil
371370
case <-ctx.Done():
372371
return nil, ctx.Err()
373-
case <-time.After(time.Second):
374-
return nil, fmt.Errorf("wait for %q timed out", name)
375372
}
376373
case "fork":
377374
var name string
@@ -385,8 +382,6 @@ func (h *handler) Handle(ctx context.Context, req *jsonrpc2.Request) (interface{
385382
h.conn.Respond(req.ID, true, nil)
386383
case <-ctx.Done():
387384
h.conn.Respond(req.ID, nil, ctx.Err())
388-
case <-time.After(time.Second):
389-
h.conn.Respond(req.ID, nil, fmt.Errorf("wait for %q timed out", name))
390385
}
391386
}()
392387
return nil, jsonrpc2.ErrAsyncResponse

internal/jsonrpc2_v2/serve_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func TestIdleTimeout(t *testing.T) {
2828
panic("TestIdleTimeout deadlocked")
2929
})
3030
defer timer.Stop()
31+
3132
ctx := context.Background()
3233

3334
try := func(d time.Duration) (longEnough bool) {
@@ -149,8 +150,7 @@ func (fakeHandler) Handle(ctx context.Context, req *jsonrpc2.Request) (interface
149150

150151
func TestServe(t *testing.T) {
151152
stacktest.NoLeak(t)
152-
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
153-
defer cancel()
153+
ctx := context.Background()
154154

155155
tests := []struct {
156156
name string
@@ -187,7 +187,6 @@ func TestServe(t *testing.T) {
187187
}
188188

189189
func newFake(t *testing.T, ctx context.Context, l jsonrpc2.Listener) (*jsonrpc2.Connection, func(), error) {
190-
l = jsonrpc2.NewIdleListener(100*time.Millisecond, l)
191190
server, err := jsonrpc2.Serve(ctx, l, jsonrpc2.ConnectionOptions{
192191
Handler: fakeHandler{},
193192
})

0 commit comments

Comments
 (0)