Skip to content

Commit

Permalink
face race in test
Browse files Browse the repository at this point in the history
  • Loading branch information
fulirockx committed Jan 4, 2024
1 parent 446bead commit 97999b9
Showing 1 changed file with 1 addition and 60 deletions.
61 changes: 1 addition & 60 deletions sess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 97999b9

Please sign in to comment.