Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: webrtc/p2p/base/portallocator_unittest.cc

Issue 2717893003: Making candidate pool size behave as decided in JSEP. (Closed)
Patch Set: Merge with master Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/portallocator.cc ('k') | webrtc/p2p/client/basicportallocator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « webrtc/p2p/base/portallocator.cc ('k') | webrtc/p2p/client/basicportallocator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698