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

Function TestCloseInConnectionStateCallback

agent_test.go:2101–2155  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2099}
2100
2101func TestCloseInConnectionStateCallback(t *testing.T) {
2102 defer test.CheckRoutines(t)()
2103
2104 defer test.TimeOut(time.Second * 5).Stop()
2105
2106 disconnectedDuration := time.Second
2107 failedDuration := time.Second
2108 KeepaliveInterval := time.Duration(0)
2109 CheckInterval := 500 * time.Millisecond
2110
2111 cfg := &AgentConfig{
2112 Urls: []*stun.URI{},
2113 NetworkTypes: supportedNetworkTypes(),
2114 DisconnectedTimeout: &disconnectedDuration,
2115 FailedTimeout: &failedDuration,
2116 KeepaliveInterval: &KeepaliveInterval,
2117 CheckInterval: &CheckInterval,
2118 }
2119
2120 aAgent, err := NewAgent(cfg)
2121 require.NoError(t, err)
2122 var aAgentClosed bool
2123 defer func() {
2124 if aAgentClosed {
2125 return
2126 }
2127 require.NoError(t, aAgent.Close())
2128 }()
2129
2130 bAgent, err := NewAgent(cfg)
2131 require.NoError(t, err)
2132 defer func() {
2133 require.NoError(t, bAgent.Close())
2134 }()
2135
2136 isClosed := make(chan any)
2137 isConnected := make(chan any)
2138 err = aAgent.OnConnectionStateChange(func(c ConnectionState) {
2139 switch c {
2140 case ConnectionStateConnected:
2141 <-isConnected
2142 require.NoError(t, aAgent.Close())
2143 aAgentClosed = true
2144 case ConnectionStateClosed:
2145 close(isClosed)
2146 default:
2147 }
2148 })
2149 require.NoError(t, err)
2150
2151 connect(t, aAgent, bAgent)
2152 close(isConnected)
2153
2154 <-isClosed
2155}
2156
2157func TestRunTaskInConnectionStateCallback(t *testing.T) {
2158 defer test.CheckRoutines(t)()

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…