Skip to content

Commit

Permalink
Test candidate WriteTo function to return error
Browse files Browse the repository at this point in the history
When connection is closed
  • Loading branch information
m1k1o authored and stv0g committed Jan 12, 2023
1 parent 049d579 commit 52b8cab
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Meelap Shah <[email protected]>
Michael MacDonald <[email protected]>
Michael MacDonald <[email protected]>
Mikhail Bragin <[email protected]>
Miroslav Šedivý <[email protected]>
Nevio Vesic <[email protected]>
Ori Bernstein <[email protected]>
Robert Eperjesi <[email protected]>
Expand Down
43 changes: 43 additions & 0 deletions candidate_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package ice

import (
"net"
"testing"
"time"

"github.com/pion/logging"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestCandidatePriority(t *testing.T) {
Expand Down Expand Up @@ -337,3 +340,43 @@ func TestCandidateMarshal(t *testing.T) {
assert.Equal(t, test.marshaled, actualCandidate.Marshal())
}
}

func TestCandidateWriteTo(t *testing.T) {
listener, err := net.ListenTCP("tcp", &net.TCPAddr{
IP: net.IP{127, 0, 0, 1},
Port: 0,
})
require.NoError(t, err, "error creating test tcp listener")

conn, err := net.DialTCP("tcp", nil, listener.Addr().(*net.TCPAddr))
require.NoError(t, err, "error dialing test tcp conn")

loggerFactory := logging.NewDefaultLoggerFactory()
packetConn := newTCPPacketConn(tcpPacketParams{
ReadBuffer: 2048,
Logger: loggerFactory.NewLogger("tcp-packet-conn"),
})

err = packetConn.AddConn(conn, nil)
require.NoError(t, err, "error adding test tcp conn to packet conn")

c1 := &candidateBase{
conn: packetConn,
currAgent: &Agent{
log: loggerFactory.NewLogger("agent"),
},
}

c2 := &candidateBase{
resolvedAddr: listener.Addr(),
}

_, err = c1.writeTo([]byte("test"), c2)
assert.NoError(t, err, "writing to open conn")

err = packetConn.Close()
require.NoError(t, err, "error closing test tcp conn")

_, err = c1.writeTo([]byte("test"), c2)
assert.Error(t, err, "writing to closed conn")
}

0 comments on commit 52b8cab

Please sign in to comment.