Test: release resources correctly

This commit is contained in:
gVisor bot 2021-09-05 14:25:55 +08:00
parent f74b7468c7
commit 8389c573db

View File

@ -214,6 +214,7 @@ func testPingPongWithSocksPort(t *testing.T, port int) {
if err != nil { if err != nil {
assert.FailNow(t, err.Error()) assert.FailNow(t, err.Error())
} }
defer l.Close()
c, err := l.Accept() c, err := l.Accept()
if err != nil { if err != nil {
@ -229,7 +230,6 @@ func testPingPongWithSocksPort(t *testing.T, port int) {
if _, err := c.Write([]byte("pong")); err != nil { if _, err := c.Write([]byte("pong")); err != nil {
assert.FailNow(t, err.Error()) assert.FailNow(t, err.Error())
} }
l.Close()
}() }()
go func() { go func() {
@ -237,6 +237,7 @@ func testPingPongWithSocksPort(t *testing.T, port int) {
if err != nil { if err != nil {
assert.FailNow(t, err.Error()) assert.FailNow(t, err.Error())
} }
defer c.Close()
if _, err := socks5.ClientHandshake(c, socks5.ParseAddr("127.0.0.1:10001"), socks5.CmdConnect, nil); err != nil { if _, err := socks5.ClientHandshake(c, socks5.ParseAddr("127.0.0.1:10001"), socks5.CmdConnect, nil); err != nil {
assert.FailNow(t, err.Error()) assert.FailNow(t, err.Error())
@ -252,7 +253,6 @@ func testPingPongWithSocksPort(t *testing.T, port int) {
} }
pongCh <- buf pongCh <- buf
c.Close()
}() }()
test(t) test(t)
@ -380,6 +380,7 @@ func testLargeDataWithConn(t *testing.T, c net.Conn) error {
if err != nil { if err != nil {
return return
} }
defer c.Close()
hashMap := map[int][]byte{} hashMap := map[int][]byte{}
buf := make([]byte, chunkSize) buf := make([]byte, chunkSize)
@ -626,15 +627,16 @@ func benchmarkProxy(b *testing.B, proxy C.ProxyAdapter) {
if err != nil { if err != nil {
assert.FailNow(b, err.Error()) assert.FailNow(b, err.Error())
} }
defer l.Close()
go func() { go func() {
c, err := l.Accept() c, err := l.Accept()
if err != nil { if err != nil {
assert.FailNow(b, err.Error()) assert.FailNow(b, err.Error())
} }
defer c.Close()
io.Copy(io.Discard, c) io.Copy(io.Discard, c)
c.Close()
}() }()
chunkSize := int64(16 * 1024) chunkSize := int64(16 * 1024)