Skip to content

Commit cffc06c

Browse files
author
Sourcegraph Bot
committed
Use t.Cleanup instead of defer in Golang code tests
1 parent 96c4efa commit cffc06c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

jsonrpc2_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func TestClientServer(t *testing.T) {
121121
if err != nil {
122122
t.Fatal("Listen:", err)
123123
}
124-
defer func() {
124+
t.Cleanup(func() {
125125
if lis == nil {
126126
return // already closed
127127
}
@@ -130,7 +130,7 @@ func TestClientServer(t *testing.T) {
130130
t.Fatal(err)
131131
}
132132
}
133-
}()
133+
})()
134134

135135
ha := testHandlerA{t: t}
136136
go func() {
@@ -184,11 +184,11 @@ func TestClientServer(t *testing.T) {
184184
func testClientServer(ctx context.Context, t *testing.T, stream jsonrpc2.ObjectStream) {
185185
hb := testHandlerB{t: t}
186186
cc := jsonrpc2.NewConn(ctx, stream, &hb)
187-
defer func() {
187+
t.Cleanup(func() {
188188
if err := cc.Close(); err != nil {
189189
t.Fatal(err)
190190
}
191-
}()
191+
})()
192192

193193
// Simple
194194
const n = 100

0 commit comments

Comments
 (0)