MCPcopy Create free account
hub / github.com/pion/ice / TestBindingRequestHandler

Function TestBindingRequestHandler

selection_test.go:70–169  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

68}
69
70func TestBindingRequestHandler(t *testing.T) {
71 defer test.CheckRoutines(t)()
72 defer test.TimeOut(time.Second * 30).Stop()
73
74 var switchToNewCandidatePair, controlledLoggingFired atomic.Value
75 oneHour := time.Hour
76 keepaliveInterval := time.Millisecond * 20
77
78 aNotifier, aConnected := onConnected()
79 bNotifier, bConnected := onConnected()
80 controllingAgent, err := NewAgent(&AgentConfig{
81 NetworkTypes: []NetworkType{NetworkTypeUDP4, NetworkTypeUDP6},
82 MulticastDNSMode: MulticastDNSModeDisabled,
83 KeepaliveInterval: &keepaliveInterval,
84 CheckInterval: &oneHour,
85 BindingRequestHandler: func(_ *stun.Message, _, _ Candidate, _ *CandidatePair) bool {
86 controlledLoggingFired.Store(true)
87
88 return false
89 },
90 })
91 require.NoError(t, err)
92 require.NoError(t, controllingAgent.OnConnectionStateChange(aNotifier))
93
94 controlledAgent, err := NewAgent(&AgentConfig{
95 NetworkTypes: []NetworkType{NetworkTypeUDP4},
96 MulticastDNSMode: MulticastDNSModeDisabled,
97 KeepaliveInterval: &keepaliveInterval,
98 CheckInterval: &oneHour,
99 BindingRequestHandler: func(_ *stun.Message, _, _ Candidate, _ *CandidatePair) bool {
100 // Don't switch candidate pair until we are ready
101 val, ok := switchToNewCandidatePair.Load().(bool)
102
103 return ok && val
104 },
105 })
106 require.NoError(t, err)
107 require.NoError(t, controlledAgent.OnConnectionStateChange(bNotifier))
108
109 controlledConn, controllingConn := connect(t, controlledAgent, controllingAgent)
110 <-aConnected
111 <-bConnected
112
113 // Assert we have connected and can send data
114 require.True(t, sendUntilDone(t, controlledConn, controllingConn, 100))
115
116 // Take the lock on the controlling Agent and unset state
117 assert.NoError(t, controlledAgent.loop.Run(controlledAgent.loop, func(_ context.Context) {
118 for net, cs := range controlledAgent.remoteCandidates {
119 for _, c := range cs {
120 require.NoError(t, c.close())
121 }
122 delete(controlledAgent.remoteCandidates, net)
123 }
124
125 for _, c := range controlledAgent.localCandidates[NetworkTypeUDP4] {
126 cast, ok := c.(*CandidateHost)
127 require.True(t, ok)

Callers

nothing calls this directly

Calls 13

setSelectedPairMethod · 0.95
onConnectedFunction · 0.85
NewAgentFunction · 0.85
connectFunction · 0.85
sendUntilDoneFunction · 0.85
closePipeFunction · 0.85
StoreMethod · 0.80
LoadMethod · 0.80
RunMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…