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 14 matching lines...) Expand all Loading... |
25 | 25 |
26 class PortAllocatorTest : public testing::Test, public sigslot::has_slots<> { | 26 class PortAllocatorTest : public testing::Test, public sigslot::has_slots<> { |
27 public: | 27 public: |
28 PortAllocatorTest() { | 28 PortAllocatorTest() { |
29 allocator_.reset( | 29 allocator_.reset( |
30 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); | 30 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); |
31 } | 31 } |
32 | 32 |
33 protected: | 33 protected: |
34 void SetConfigurationWithPoolSize(int candidate_pool_size) { | 34 void SetConfigurationWithPoolSize(int candidate_pool_size) { |
35 allocator_->SetConfiguration(cricket::ServerAddresses(), | 35 EXPECT_TRUE(allocator_->SetConfiguration( |
36 std::vector<cricket::RelayServerConfig>(), | 36 cricket::ServerAddresses(), std::vector<cricket::RelayServerConfig>(), |
37 candidate_pool_size, false); | 37 candidate_pool_size, false)); |
| 38 } |
| 39 |
| 40 void SetConfigurationWithPoolSizeExpectFailure(int candidate_pool_size) { |
| 41 EXPECT_FALSE(allocator_->SetConfiguration( |
| 42 cricket::ServerAddresses(), std::vector<cricket::RelayServerConfig>(), |
| 43 candidate_pool_size, false)); |
38 } | 44 } |
39 | 45 |
40 std::unique_ptr<cricket::FakePortAllocatorSession> CreateSession( | 46 std::unique_ptr<cricket::FakePortAllocatorSession> CreateSession( |
41 const std::string& content_name, | 47 const std::string& content_name, |
42 int component, | 48 int component, |
43 const std::string& ice_ufrag, | 49 const std::string& ice_ufrag, |
44 const std::string& ice_pwd) { | 50 const std::string& ice_pwd) { |
45 return std::unique_ptr<cricket::FakePortAllocatorSession>( | 51 return std::unique_ptr<cricket::FakePortAllocatorSession>( |
46 static_cast<cricket::FakePortAllocatorSession*>( | 52 static_cast<cricket::FakePortAllocatorSession*>( |
47 allocator_ | 53 allocator_ |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); | 103 EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); |
98 EXPECT_EQ(kContentName, session->content_name()); | 104 EXPECT_EQ(kContentName, session->content_name()); |
99 EXPECT_EQ(1, session->component()); | 105 EXPECT_EQ(1, session->component()); |
100 EXPECT_EQ(kIceUfrag, session->ice_ufrag()); | 106 EXPECT_EQ(kIceUfrag, session->ice_ufrag()); |
101 EXPECT_EQ(kIcePwd, session->ice_pwd()); | 107 EXPECT_EQ(kIcePwd, session->ice_pwd()); |
102 } | 108 } |
103 | 109 |
104 TEST_F(PortAllocatorTest, SetConfigurationUpdatesIceServers) { | 110 TEST_F(PortAllocatorTest, SetConfigurationUpdatesIceServers) { |
105 cricket::ServerAddresses stun_servers_1 = {stun_server_1}; | 111 cricket::ServerAddresses stun_servers_1 = {stun_server_1}; |
106 std::vector<cricket::RelayServerConfig> turn_servers_1 = {turn_server_1}; | 112 std::vector<cricket::RelayServerConfig> turn_servers_1 = {turn_server_1}; |
107 allocator_->SetConfiguration(stun_servers_1, turn_servers_1, 0, false); | 113 EXPECT_TRUE( |
| 114 allocator_->SetConfiguration(stun_servers_1, turn_servers_1, 0, false)); |
108 EXPECT_EQ(stun_servers_1, allocator_->stun_servers()); | 115 EXPECT_EQ(stun_servers_1, allocator_->stun_servers()); |
109 EXPECT_EQ(turn_servers_1, allocator_->turn_servers()); | 116 EXPECT_EQ(turn_servers_1, allocator_->turn_servers()); |
110 | 117 |
111 // Update with a different set of servers. | 118 // Update with a different set of servers. |
112 cricket::ServerAddresses stun_servers_2 = {stun_server_2}; | 119 cricket::ServerAddresses stun_servers_2 = {stun_server_2}; |
113 std::vector<cricket::RelayServerConfig> turn_servers_2 = {turn_server_2}; | 120 std::vector<cricket::RelayServerConfig> turn_servers_2 = {turn_server_2}; |
114 allocator_->SetConfiguration(stun_servers_2, turn_servers_2, 0, false); | 121 EXPECT_TRUE( |
| 122 allocator_->SetConfiguration(stun_servers_2, turn_servers_2, 0, false)); |
115 EXPECT_EQ(stun_servers_2, allocator_->stun_servers()); | 123 EXPECT_EQ(stun_servers_2, allocator_->stun_servers()); |
116 EXPECT_EQ(turn_servers_2, allocator_->turn_servers()); | 124 EXPECT_EQ(turn_servers_2, allocator_->turn_servers()); |
117 } | 125 } |
118 | 126 |
119 TEST_F(PortAllocatorTest, SetConfigurationUpdatesCandidatePoolSize) { | 127 TEST_F(PortAllocatorTest, SetConfigurationUpdatesCandidatePoolSize) { |
120 SetConfigurationWithPoolSize(2); | 128 SetConfigurationWithPoolSize(2); |
121 EXPECT_EQ(2, allocator_->candidate_pool_size()); | 129 EXPECT_EQ(2, allocator_->candidate_pool_size()); |
122 SetConfigurationWithPoolSize(3); | 130 SetConfigurationWithPoolSize(3); |
123 EXPECT_EQ(3, allocator_->candidate_pool_size()); | 131 EXPECT_EQ(3, allocator_->candidate_pool_size()); |
124 SetConfigurationWithPoolSize(1); | 132 SetConfigurationWithPoolSize(1); |
125 EXPECT_EQ(1, allocator_->candidate_pool_size()); | 133 EXPECT_EQ(1, allocator_->candidate_pool_size()); |
126 SetConfigurationWithPoolSize(4); | 134 SetConfigurationWithPoolSize(4); |
127 EXPECT_EQ(4, allocator_->candidate_pool_size()); | 135 EXPECT_EQ(4, allocator_->candidate_pool_size()); |
128 } | 136 } |
129 | 137 |
130 // A negative pool size should just be treated as zero. | 138 // A negative pool size should just be treated as zero. |
131 TEST_F(PortAllocatorTest, SetConfigurationWithNegativePoolSizeDoesntCrash) { | 139 TEST_F(PortAllocatorTest, SetConfigurationWithNegativePoolSizeFails) { |
132 SetConfigurationWithPoolSize(-1); | 140 SetConfigurationWithPoolSizeExpectFailure(-1); |
133 // No asserts; we're just testing that this doesn't crash. | |
134 } | 141 } |
135 | 142 |
136 // Test that if the candidate pool size is nonzero, pooled sessions are | 143 // Test that if the candidate pool size is nonzero, pooled sessions are |
137 // created, and StartGettingPorts is called on them. | 144 // created, and StartGettingPorts is called on them. |
138 TEST_F(PortAllocatorTest, SetConfigurationCreatesPooledSessions) { | 145 TEST_F(PortAllocatorTest, SetConfigurationCreatesPooledSessions) { |
139 SetConfigurationWithPoolSize(2); | 146 SetConfigurationWithPoolSize(2); |
140 auto session_1 = TakePooledSession(); | 147 auto session_1 = TakePooledSession(); |
141 auto session_2 = TakePooledSession(); | 148 auto session_2 = TakePooledSession(); |
142 ASSERT_NE(nullptr, session_1.get()); | 149 ASSERT_NE(nullptr, session_1.get()); |
143 ASSERT_NE(nullptr, session_2.get()); | 150 ASSERT_NE(nullptr, session_2.get()); |
(...skipping 11 matching lines...) Expand all Loading... |
155 } | 162 } |
156 | 163 |
157 // 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 |
158 // destroyed. | 165 // destroyed. |
159 TEST_F(PortAllocatorTest, SetConfigurationDestroysPooledSessions) { | 166 TEST_F(PortAllocatorTest, SetConfigurationDestroysPooledSessions) { |
160 SetConfigurationWithPoolSize(2); | 167 SetConfigurationWithPoolSize(2); |
161 SetConfigurationWithPoolSize(1); | 168 SetConfigurationWithPoolSize(1); |
162 EXPECT_EQ(1, GetAllPooledSessionsReturnCount()); | 169 EXPECT_EQ(1, GetAllPooledSessionsReturnCount()); |
163 } | 170 } |
164 | 171 |
165 // Test that if the candidate pool size is reduced and increased, but reducing | 172 // Test that after the pool starts to be drained, changing the pool size is not |
166 // didn't actually destroy any sessions (because they were already given away), | 173 // allowed. |
167 // increasing the size to its initial value doesn't create a new session. | 174 TEST_F(PortAllocatorTest, CantChangePoolSizeAfterTakePooledSession) { |
168 TEST_F(PortAllocatorTest, SetConfigurationDoesntCreateExtraSessions) { | |
169 SetConfigurationWithPoolSize(1); | 175 SetConfigurationWithPoolSize(1); |
170 TakePooledSession(); | 176 TakePooledSession(); |
171 SetConfigurationWithPoolSize(0); | 177 SetConfigurationWithPoolSizeExpectFailure(2); |
172 SetConfigurationWithPoolSize(1); | 178 SetConfigurationWithPoolSizeExpectFailure(0); |
173 EXPECT_EQ(0, GetAllPooledSessionsReturnCount()); | |
174 } | 179 } |
175 | 180 |
176 // According to JSEP, exising pooled sessions should be destroyed and new | 181 // According to JSEP, existing pooled sessions should be destroyed and new |
177 // ones created when the ICE servers change. | 182 // ones created when the ICE servers change. |
178 TEST_F(PortAllocatorTest, | 183 TEST_F(PortAllocatorTest, |
179 SetConfigurationRecreatesPooledSessionsWhenIceServersChange) { | 184 SetConfigurationRecreatesPooledSessionsWhenIceServersChange) { |
180 cricket::ServerAddresses stun_servers_1 = {stun_server_1}; | 185 cricket::ServerAddresses stun_servers_1 = {stun_server_1}; |
181 std::vector<cricket::RelayServerConfig> turn_servers_1 = {turn_server_1}; | 186 std::vector<cricket::RelayServerConfig> turn_servers_1 = {turn_server_1}; |
182 allocator_->SetConfiguration(stun_servers_1, turn_servers_1, 1, false); | 187 allocator_->SetConfiguration(stun_servers_1, turn_servers_1, 1, false); |
183 EXPECT_EQ(stun_servers_1, allocator_->stun_servers()); | 188 EXPECT_EQ(stun_servers_1, allocator_->stun_servers()); |
184 EXPECT_EQ(turn_servers_1, allocator_->turn_servers()); | 189 EXPECT_EQ(turn_servers_1, allocator_->turn_servers()); |
185 | 190 |
186 // Update with a different set of servers (and also change pool size). | 191 // Update with a different set of servers (and also change pool size). |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 // unfiltered until it's returned by TakePooledSession. | 240 // unfiltered until it's returned by TakePooledSession. |
236 TEST_F(PortAllocatorTest, TakePooledSessionUpdatesCandidateFilter) { | 241 TEST_F(PortAllocatorTest, TakePooledSessionUpdatesCandidateFilter) { |
237 allocator_->set_candidate_filter(cricket::CF_RELAY); | 242 allocator_->set_candidate_filter(cricket::CF_RELAY); |
238 SetConfigurationWithPoolSize(1); | 243 SetConfigurationWithPoolSize(1); |
239 auto peeked_session = GetPooledSession(); | 244 auto peeked_session = GetPooledSession(); |
240 ASSERT_NE(nullptr, peeked_session); | 245 ASSERT_NE(nullptr, peeked_session); |
241 EXPECT_EQ(cricket::CF_ALL, peeked_session->candidate_filter()); | 246 EXPECT_EQ(cricket::CF_ALL, peeked_session->candidate_filter()); |
242 auto session = TakePooledSession(); | 247 auto session = TakePooledSession(); |
243 EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); | 248 EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); |
244 } | 249 } |
OLD | NEW |