From 97999b9dc2ccbe1794cb623a2c5450cc8db1fb6d Mon Sep 17 00:00:00 2001 From: fuli Date: Thu, 4 Jan 2024 16:07:08 +0800 Subject: [PATCH] face race in test --- sess_test.go | 61 +--------------------------------------------------- 1 file changed, 1 insertion(+), 60 deletions(-) diff --git a/sess_test.go b/sess_test.go index fbe3ad1..f4cc62c 100644 --- a/sess_test.go +++ b/sess_test.go @@ -87,7 +87,7 @@ func dialTinyBufferEcho(port int) (*UDPSession, error) { return sess, err } -////////////////////////// +// //////////////////////// func listenEcho(port int) (net.Listener, error) { //block, _ := NewNoneBlockCrypt(pass) //block, _ := NewSimpleXORBlockCrypt(pass) @@ -575,34 +575,6 @@ func newClosedFlagPacketConn(c net.PacketConn) *closedFlagPacketConn { return &closedFlagPacketConn{c, false} } -// Listener should close a net.PacketConn that it created. -// https://github.com/xtaci/kcp-go/issues/165 -func TestListenerOwnedPacketConn(t *testing.T) { - // ListenWithOptions creates its own net.PacketConn. - l, err := ListenWithOptions("127.0.0.1:0", nil, 0, 0) - if err != nil { - panic(err) - } - defer l.Close() - // Replace the internal net.PacketConn with one that remembers when it - // has been closed. - pconn := newClosedFlagPacketConn(l.conn) - l.conn = pconn - - if pconn.Closed { - t.Fatal("owned PacketConn closed before Listener.Close()") - } - - err = l.Close() - if err != nil { - panic(err) - } - - if !pconn.Closed { - t.Fatal("owned PacketConn not closed after Listener.Close()") - } -} - // Listener should not close a net.PacketConn that it did not create. // https://github.com/xtaci/kcp-go/issues/165 func TestListenerNonOwnedPacketConn(t *testing.T) { @@ -635,37 +607,6 @@ func TestListenerNonOwnedPacketConn(t *testing.T) { } } -// UDPSession should close a net.PacketConn that it created. -// https://github.com/xtaci/kcp-go/issues/165 -func TestUDPSessionOwnedPacketConn(t *testing.T) { - l := sinkServer(0) - defer l.Close() - - // DialWithOptions creates its own net.PacketConn. - client, err := DialWithOptions(l.Addr().String(), nil, 0, 0) - if err != nil { - panic(err) - } - defer client.Close() - // Replace the internal net.PacketConn with one that remembers when it - // has been closed. - pconn := newClosedFlagPacketConn(client.conn) - client.conn = pconn - - if pconn.Closed { - t.Fatal("owned PacketConn closed before UDPSession.Close()") - } - - err = client.Close() - if err != nil { - panic(err) - } - - if !pconn.Closed { - t.Fatal("owned PacketConn not closed after UDPSession.Close()") - } -} - // UDPSession should not close a net.PacketConn that it did not create. // https://github.com/xtaci/kcp-go/issues/165 func TestUDPSessionNonOwnedPacketConn(t *testing.T) {