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

Function TestConnectionStateCallback

agent_test.go:1167–1241  ·  view source on GitHub ↗

Assert that Agent emits Connecting/Connected/Disconnected/Failed/Closed messages.

(t *testing.T)

Source from the content-addressed store, hash-verified

1165
1166// Assert that Agent emits Connecting/Connected/Disconnected/Failed/Closed messages.
1167func TestConnectionStateCallback(t *testing.T) { //nolint:cyclop
1168 defer test.CheckRoutines(t)()
1169
1170 defer test.TimeOut(time.Second * 5).Stop()
1171
1172 disconnectedDuration := time.Second
1173 failedDuration := time.Second
1174 KeepaliveInterval := time.Duration(0)
1175
1176 cfg := &AgentConfig{
1177 Urls: []*stun.URI{},
1178 NetworkTypes: supportedNetworkTypes(),
1179 DisconnectedTimeout: &disconnectedDuration,
1180 FailedTimeout: &failedDuration,
1181 KeepaliveInterval: &KeepaliveInterval,
1182 InterfaceFilter: problematicNetworkInterfaces,
1183 }
1184
1185 isClosed := make(chan any)
1186
1187 aAgent, err := NewAgent(cfg)
1188 require.NoError(t, err)
1189 defer func() {
1190 select {
1191 case <-isClosed:
1192 return
1193 default:
1194 }
1195 require.NoError(t, aAgent.Close())
1196 }()
1197
1198 bAgent, err := NewAgent(cfg)
1199 require.NoError(t, err)
1200 defer func() {
1201 select {
1202 case <-isClosed:
1203 return
1204 default:
1205 }
1206 require.NoError(t, bAgent.Close())
1207 }()
1208
1209 isChecking := make(chan any)
1210 isConnected := make(chan any)
1211 isDisconnected := make(chan any)
1212 isFailed := make(chan any)
1213 err = aAgent.OnConnectionStateChange(func(c ConnectionState) {
1214 switch c {
1215 case ConnectionStateChecking:
1216 close(isChecking)
1217 case ConnectionStateConnected:
1218 close(isConnected)
1219 case ConnectionStateDisconnected:
1220 close(isDisconnected)
1221 case ConnectionStateFailed:
1222 close(isFailed)
1223 case ConnectionStateClosed:
1224 close(isClosed)

Callers

nothing calls this directly

Calls 5

CloseMethod · 0.95
supportedNetworkTypesFunction · 0.85
NewAgentFunction · 0.85
connectFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…