mirror of https://github.com/golang/go.git
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 <bcmills@google.com> Reviewed-by: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
This commit is contained in:
parent
371ef162f2
commit
b2efd4d155
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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{},
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue