mirror of
https://github.com/pion/ice.git
synced 2025-10-05 23:47:01 +08:00
Extract TestPairPriority
to separate file
This commit is contained in:

committed by
Arthur Shellunts

parent
228c31f051
commit
b7897a6b72
95
agent_pair_priority_test.go
Normal file
95
agent_pair_priority_test.go
Normal file
@@ -0,0 +1,95 @@
|
||||
//go:build !js
|
||||
// +build !js
|
||||
|
||||
package ice
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPairPriority(t *testing.T) {
|
||||
|
||||
a, err := NewAgent(&AgentConfig{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create agent: %s", err)
|
||||
}
|
||||
|
||||
hostConfig := &CandidateHostConfig{
|
||||
Network: "udp",
|
||||
Address: "192.168.1.1",
|
||||
Port: 19216,
|
||||
Component: 1,
|
||||
}
|
||||
hostLocal, err := NewCandidateHost(hostConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to construct local host candidate: %s", err)
|
||||
}
|
||||
|
||||
relayConfig := &CandidateRelayConfig{
|
||||
Network: "udp",
|
||||
Address: "1.2.3.4",
|
||||
Port: 12340,
|
||||
Component: 1,
|
||||
RelAddr: "4.3.2.1",
|
||||
RelPort: 43210,
|
||||
}
|
||||
relayRemote, err := NewCandidateRelay(relayConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to construct remote relay candidate: %s", err)
|
||||
}
|
||||
|
||||
srflxConfig := &CandidateServerReflexiveConfig{
|
||||
Network: "udp",
|
||||
Address: "10.10.10.2",
|
||||
Port: 19218,
|
||||
Component: 1,
|
||||
RelAddr: "4.3.2.1",
|
||||
RelPort: 43212,
|
||||
}
|
||||
srflxRemote, err := NewCandidateServerReflexive(srflxConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to construct remote srflx candidate: %s", err)
|
||||
}
|
||||
|
||||
prflxConfig := &CandidatePeerReflexiveConfig{
|
||||
Network: "udp",
|
||||
Address: "10.10.10.2",
|
||||
Port: 19217,
|
||||
Component: 1,
|
||||
RelAddr: "4.3.2.1",
|
||||
RelPort: 43211,
|
||||
}
|
||||
prflxRemote, err := NewCandidatePeerReflexive(prflxConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to construct remote prflx candidate: %s", err)
|
||||
}
|
||||
|
||||
hostConfig = &CandidateHostConfig{
|
||||
Network: "udp",
|
||||
Address: "1.2.3.5",
|
||||
Port: 12350,
|
||||
Component: 1,
|
||||
}
|
||||
hostRemote, err := NewCandidateHost(hostConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to construct remote host candidate: %s", err)
|
||||
}
|
||||
|
||||
for _, remote := range []Candidate{relayRemote, srflxRemote, prflxRemote, hostRemote} {
|
||||
p := a.findPair(hostLocal, remote)
|
||||
|
||||
if p == nil {
|
||||
p = a.addPair(hostLocal, remote)
|
||||
}
|
||||
|
||||
p.state = CandidatePairStateSucceeded
|
||||
bestPair := a.getBestValidCandidatePair()
|
||||
if bestPair.String() != (&CandidatePair{Remote: remote, Local: hostLocal}).String() {
|
||||
t.Fatalf("Unexpected bestPair %s (expected remote: %s)", bestPair, remote)
|
||||
}
|
||||
}
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
}
|
@@ -31,96 +31,6 @@ func (m *mockPacketConn) SetDeadline(t time.Time) error {
|
||||
func (m *mockPacketConn) SetReadDeadline(t time.Time) error { return nil }
|
||||
func (m *mockPacketConn) SetWriteDeadline(t time.Time) error { return nil }
|
||||
|
||||
func TestPairPriority(t *testing.T) {
|
||||
report := test.CheckRoutines(t)
|
||||
defer report()
|
||||
|
||||
// avoid deadlocks?
|
||||
defer test.TimeOut(1 * time.Second).Stop()
|
||||
|
||||
a, err := NewAgent(&AgentConfig{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create agent: %s", err)
|
||||
}
|
||||
|
||||
hostConfig := &CandidateHostConfig{
|
||||
Network: "udp",
|
||||
Address: "192.168.1.1",
|
||||
Port: 19216,
|
||||
Component: 1,
|
||||
}
|
||||
hostLocal, err := NewCandidateHost(hostConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to construct local host candidate: %s", err)
|
||||
}
|
||||
|
||||
relayConfig := &CandidateRelayConfig{
|
||||
Network: "udp",
|
||||
Address: "1.2.3.4",
|
||||
Port: 12340,
|
||||
Component: 1,
|
||||
RelAddr: "4.3.2.1",
|
||||
RelPort: 43210,
|
||||
}
|
||||
relayRemote, err := NewCandidateRelay(relayConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to construct remote relay candidate: %s", err)
|
||||
}
|
||||
|
||||
srflxConfig := &CandidateServerReflexiveConfig{
|
||||
Network: "udp",
|
||||
Address: "10.10.10.2",
|
||||
Port: 19218,
|
||||
Component: 1,
|
||||
RelAddr: "4.3.2.1",
|
||||
RelPort: 43212,
|
||||
}
|
||||
srflxRemote, err := NewCandidateServerReflexive(srflxConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to construct remote srflx candidate: %s", err)
|
||||
}
|
||||
|
||||
prflxConfig := &CandidatePeerReflexiveConfig{
|
||||
Network: "udp",
|
||||
Address: "10.10.10.2",
|
||||
Port: 19217,
|
||||
Component: 1,
|
||||
RelAddr: "4.3.2.1",
|
||||
RelPort: 43211,
|
||||
}
|
||||
prflxRemote, err := NewCandidatePeerReflexive(prflxConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to construct remote prflx candidate: %s", err)
|
||||
}
|
||||
|
||||
hostConfig = &CandidateHostConfig{
|
||||
Network: "udp",
|
||||
Address: "1.2.3.5",
|
||||
Port: 12350,
|
||||
Component: 1,
|
||||
}
|
||||
hostRemote, err := NewCandidateHost(hostConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to construct remote host candidate: %s", err)
|
||||
}
|
||||
|
||||
for _, remote := range []Candidate{relayRemote, srflxRemote, prflxRemote, hostRemote} {
|
||||
p := a.findPair(hostLocal, remote)
|
||||
|
||||
if p == nil {
|
||||
p = a.addPair(hostLocal, remote)
|
||||
}
|
||||
|
||||
p.state = CandidatePairStateSucceeded
|
||||
bestPair := a.getBestValidCandidatePair()
|
||||
if bestPair.String() != (&CandidatePair{Remote: remote, Local: hostLocal}).String() {
|
||||
t.Fatalf("Unexpected bestPair %s (expected remote: %s)", bestPair, remote)
|
||||
}
|
||||
}
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
}
|
||||
|
||||
func TestOnSelectedCandidatePairChange(t *testing.T) {
|
||||
report := test.CheckRoutines(t)
|
||||
defer report()
|
||||
|
Reference in New Issue
Block a user