1
0
Fork 0
mirror of https://github.com/sourcegraph/jsonrpc2.git synced 2026-06-16 04:04:56 +02:00

Use t.Cleanup instead of defer in Golang code tests

This commit is contained in:
Sourcegraph Bot 2020-04-28 15:58:19 +00:00
parent 96c4efab7e
commit 01ce4c18a2

View file

@ -121,7 +121,7 @@ func TestClientServer(t *testing.T) {
if err != nil { if err != nil {
t.Fatal("Listen:", err) t.Fatal("Listen:", err)
} }
defer func() { t.Cleanup(func() {
if lis == nil { if lis == nil {
return // already closed return // already closed
} }
@ -130,7 +130,7 @@ func TestClientServer(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
} }
}() })
ha := testHandlerA{t: t} ha := testHandlerA{t: t}
go func() { go func() {
@ -184,11 +184,11 @@ func TestClientServer(t *testing.T) {
func testClientServer(ctx context.Context, t *testing.T, stream jsonrpc2.ObjectStream) { func testClientServer(ctx context.Context, t *testing.T, stream jsonrpc2.ObjectStream) {
hb := testHandlerB{t: t} hb := testHandlerB{t: t}
cc := jsonrpc2.NewConn(ctx, stream, &hb) cc := jsonrpc2.NewConn(ctx, stream, &hb)
defer func() { t.Cleanup(func() {
if err := cc.Close(); err != nil { if err := cc.Close(); err != nil {
t.Fatal(err) t.Fatal(err)
} }
}() })
// Simple // Simple
const n = 100 const n = 100