OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 } | 162 } |
163 | 163 |
164 // Test that if the candidate pool size is reduced, extra sessions are | 164 // Test that if the candidate pool size is reduced, extra sessions are |
165 // destroyed. | 165 // destroyed. |
166 TEST_F(PortAllocatorTest, SetConfigurationDestroysPooledSessions) { | 166 TEST_F(PortAllocatorTest, SetConfigurationDestroysPooledSessions) { |
167 SetConfigurationWithPoolSize(2); | 167 SetConfigurationWithPoolSize(2); |
168 SetConfigurationWithPoolSize(1); | 168 SetConfigurationWithPoolSize(1); |
169 EXPECT_EQ(1, GetAllPooledSessionsReturnCount()); | 169 EXPECT_EQ(1, GetAllPooledSessionsReturnCount()); |
170 } | 170 } |
171 | 171 |
172 // Test that after the pool starts to be drained, changing the pool size is not | |
173 // allowed. | |
174 TEST_F(PortAllocatorTest, CantChangePoolSizeAfterTakePooledSession) { | |
175 SetConfigurationWithPoolSize(1); | |
176 TakePooledSession(); | |
177 SetConfigurationWithPoolSizeExpectFailure(2); | |
178 SetConfigurationWithPoolSizeExpectFailure(0); | |
179 } | |
180 | |
181 // According to JSEP, existing pooled sessions should be destroyed and new | 172 // According to JSEP, existing pooled sessions should be destroyed and new |
182 // ones created when the ICE servers change. | 173 // ones created when the ICE servers change. |
183 TEST_F(PortAllocatorTest, | 174 TEST_F(PortAllocatorTest, |
184 SetConfigurationRecreatesPooledSessionsWhenIceServersChange) { | 175 SetConfigurationRecreatesPooledSessionsWhenIceServersChange) { |
185 cricket::ServerAddresses stun_servers_1 = {stun_server_1}; | 176 cricket::ServerAddresses stun_servers_1 = {stun_server_1}; |
186 std::vector<cricket::RelayServerConfig> turn_servers_1 = {turn_server_1}; | 177 std::vector<cricket::RelayServerConfig> turn_servers_1 = {turn_server_1}; |
187 allocator_->SetConfiguration(stun_servers_1, turn_servers_1, 1, false); | 178 allocator_->SetConfiguration(stun_servers_1, turn_servers_1, 1, false); |
188 EXPECT_EQ(stun_servers_1, allocator_->stun_servers()); | 179 EXPECT_EQ(stun_servers_1, allocator_->stun_servers()); |
189 EXPECT_EQ(turn_servers_1, allocator_->turn_servers()); | 180 EXPECT_EQ(turn_servers_1, allocator_->turn_servers()); |
190 | 181 |
191 // Update with a different set of servers (and also change pool size). | 182 // Update with a different set of servers (and also change pool size). |
192 cricket::ServerAddresses stun_servers_2 = {stun_server_2}; | 183 cricket::ServerAddresses stun_servers_2 = {stun_server_2}; |
193 std::vector<cricket::RelayServerConfig> turn_servers_2 = {turn_server_2}; | 184 std::vector<cricket::RelayServerConfig> turn_servers_2 = {turn_server_2}; |
194 allocator_->SetConfiguration(stun_servers_2, turn_servers_2, 2, false); | 185 allocator_->SetConfiguration(stun_servers_2, turn_servers_2, 2, false); |
195 EXPECT_EQ(stun_servers_2, allocator_->stun_servers()); | 186 EXPECT_EQ(stun_servers_2, allocator_->stun_servers()); |
196 EXPECT_EQ(turn_servers_2, allocator_->turn_servers()); | 187 EXPECT_EQ(turn_servers_2, allocator_->turn_servers()); |
197 auto session_1 = TakePooledSession(); | 188 auto session_1 = TakePooledSession(); |
198 auto session_2 = TakePooledSession(); | 189 auto session_2 = TakePooledSession(); |
199 ASSERT_NE(nullptr, session_1.get()); | 190 ASSERT_NE(nullptr, session_1.get()); |
200 ASSERT_NE(nullptr, session_2.get()); | 191 ASSERT_NE(nullptr, session_2.get()); |
201 EXPECT_EQ(stun_servers_2, session_1->stun_servers()); | 192 EXPECT_EQ(stun_servers_2, session_1->stun_servers()); |
202 EXPECT_EQ(turn_servers_2, session_1->turn_servers()); | 193 EXPECT_EQ(turn_servers_2, session_1->turn_servers()); |
203 EXPECT_EQ(stun_servers_2, session_2->stun_servers()); | 194 EXPECT_EQ(stun_servers_2, session_2->stun_servers()); |
204 EXPECT_EQ(turn_servers_2, session_2->turn_servers()); | 195 EXPECT_EQ(turn_servers_2, session_2->turn_servers()); |
205 EXPECT_EQ(0, GetAllPooledSessionsReturnCount()); | 196 EXPECT_EQ(0, GetAllPooledSessionsReturnCount()); |
206 } | 197 } |
207 | 198 |
| 199 // According to JSEP, after SetLocalDescription, setting different ICE servers |
| 200 // will not cause the pool to be refilled. This is implemented by the |
| 201 // PeerConnection calling FreezeCandidatePool when a local description is set. |
| 202 TEST_F(PortAllocatorTest, |
| 203 SetConfigurationDoesNotRecreatePooledSessionsAfterFreezeCandidatePool) { |
| 204 cricket::ServerAddresses stun_servers_1 = {stun_server_1}; |
| 205 std::vector<cricket::RelayServerConfig> turn_servers_1 = {turn_server_1}; |
| 206 allocator_->SetConfiguration(stun_servers_1, turn_servers_1, 1, false); |
| 207 EXPECT_EQ(stun_servers_1, allocator_->stun_servers()); |
| 208 EXPECT_EQ(turn_servers_1, allocator_->turn_servers()); |
| 209 |
| 210 // Update with a different set of servers, but first freeze the pool. |
| 211 allocator_->FreezeCandidatePool(); |
| 212 cricket::ServerAddresses stun_servers_2 = {stun_server_2}; |
| 213 std::vector<cricket::RelayServerConfig> turn_servers_2 = {turn_server_2}; |
| 214 allocator_->SetConfiguration(stun_servers_2, turn_servers_2, 2, false); |
| 215 EXPECT_EQ(stun_servers_2, allocator_->stun_servers()); |
| 216 EXPECT_EQ(turn_servers_2, allocator_->turn_servers()); |
| 217 auto session = TakePooledSession(); |
| 218 ASSERT_NE(nullptr, session.get()); |
| 219 EXPECT_EQ(stun_servers_1, session->stun_servers()); |
| 220 EXPECT_EQ(turn_servers_1, session->turn_servers()); |
| 221 EXPECT_EQ(0, GetAllPooledSessionsReturnCount()); |
| 222 } |
| 223 |
208 TEST_F(PortAllocatorTest, GetPooledSessionReturnsNextSession) { | 224 TEST_F(PortAllocatorTest, GetPooledSessionReturnsNextSession) { |
209 SetConfigurationWithPoolSize(2); | 225 SetConfigurationWithPoolSize(2); |
210 auto peeked_session_1 = GetPooledSession(); | 226 auto peeked_session_1 = GetPooledSession(); |
211 auto session_1 = TakePooledSession(); | 227 auto session_1 = TakePooledSession(); |
212 EXPECT_EQ(session_1.get(), peeked_session_1); | 228 EXPECT_EQ(session_1.get(), peeked_session_1); |
213 auto peeked_session_2 = GetPooledSession(); | 229 auto peeked_session_2 = GetPooledSession(); |
214 auto session_2 = TakePooledSession(); | 230 auto session_2 = TakePooledSession(); |
215 EXPECT_EQ(session_2.get(), peeked_session_2); | 231 EXPECT_EQ(session_2.get(), peeked_session_2); |
216 } | 232 } |
217 | 233 |
(...skipping 22 matching lines...) Expand all Loading... |
240 // unfiltered until it's returned by TakePooledSession. | 256 // unfiltered until it's returned by TakePooledSession. |
241 TEST_F(PortAllocatorTest, TakePooledSessionUpdatesCandidateFilter) { | 257 TEST_F(PortAllocatorTest, TakePooledSessionUpdatesCandidateFilter) { |
242 allocator_->set_candidate_filter(cricket::CF_RELAY); | 258 allocator_->set_candidate_filter(cricket::CF_RELAY); |
243 SetConfigurationWithPoolSize(1); | 259 SetConfigurationWithPoolSize(1); |
244 auto peeked_session = GetPooledSession(); | 260 auto peeked_session = GetPooledSession(); |
245 ASSERT_NE(nullptr, peeked_session); | 261 ASSERT_NE(nullptr, peeked_session); |
246 EXPECT_EQ(cricket::CF_ALL, peeked_session->candidate_filter()); | 262 EXPECT_EQ(cricket::CF_ALL, peeked_session->candidate_filter()); |
247 auto session = TakePooledSession(); | 263 auto session = TakePooledSession(); |
248 EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); | 264 EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); |
249 } | 265 } |
| 266 |
| 267 // Verify that after DiscardCandidatePool, TakePooledSession doesn't return |
| 268 // anything. |
| 269 TEST_F(PortAllocatorTest, DiscardCandidatePool) { |
| 270 SetConfigurationWithPoolSize(1); |
| 271 allocator_->DiscardCandidatePool(); |
| 272 EXPECT_EQ(0, GetAllPooledSessionsReturnCount()); |
| 273 } |
OLD | NEW |