|
8 | 8 | using System.Text; |
9 | 9 | using UnityEngine; |
10 | 10 | using UnityEngine.TestTools; |
11 | | -using Unity.Netcode.UTP.Utilities; |
12 | 11 | using static Unity.Netcode.UTP.RuntimeTests.RuntimeTestsHelpers; |
13 | 12 |
|
14 | 13 | namespace Unity.Netcode.UTP.RuntimeTests |
@@ -161,44 +160,6 @@ public IEnumerator SendMaximumPayloadSize([ValueSource("k_DeliveryParameters")] |
161 | 160 | yield return null; |
162 | 161 | } |
163 | 162 |
|
164 | | - [UnityTest] |
165 | | - public IEnumerator FilledSendQueueMultipleSends([ValueSource("k_DeliveryParameters")] NetworkDelivery delivery) |
166 | | - { |
167 | | - InitializeTransport(out m_Server, out m_ServerEvents); |
168 | | - InitializeTransport(out m_Client1, out m_Client1Events); |
169 | | - |
170 | | - m_Server.StartServer(); |
171 | | - m_Client1.StartClient(); |
172 | | - |
173 | | - yield return WaitForNetworkEvent(NetworkEvent.Connect, m_Client1Events); |
174 | | - |
175 | | - var numSends = UnityTransport.InitialMaxSendQueueSize / 1024; |
176 | | - |
177 | | - for (int i = 0; i < numSends; i++) |
178 | | - { |
179 | | - // We remove 4 bytes because each send carries a 4 bytes overhead in the send queue. |
180 | | - // Without that we wouldn't fill the send queue; it would get flushed right when we |
181 | | - // try to send the last message. |
182 | | - var payload = new ArraySegment<byte>(new byte[1024 - BatchedSendQueue.PerMessageOverhead]); |
183 | | - m_Client1.Send(m_Client1.ServerClientId, payload, delivery); |
184 | | - } |
185 | | - |
186 | | - // Manually wait. This ends up generating quite a bit of packets and it might take a |
187 | | - // while for everything to make it to the server. |
188 | | - yield return new WaitForSeconds(numSends * 0.02f); |
189 | | - |
190 | | - // Extra event is the connect event. |
191 | | - Assert.AreEqual(numSends + 1, m_ServerEvents.Count); |
192 | | - |
193 | | - for (int i = 1; i <= numSends; i++) |
194 | | - { |
195 | | - Assert.AreEqual(NetworkEvent.Data, m_ServerEvents[i].Type); |
196 | | - Assert.AreEqual(1024 - BatchedSendQueue.PerMessageOverhead, m_ServerEvents[i].Data.Count); |
197 | | - } |
198 | | - |
199 | | - yield return null; |
200 | | - } |
201 | | - |
202 | 163 | // Check making multiple sends to a client in a single frame. |
203 | 164 | [UnityTest] |
204 | 165 | public IEnumerator MultipleSendsSingleFrame([ValueSource("k_DeliveryParameters")] NetworkDelivery delivery) |
@@ -305,6 +266,74 @@ public IEnumerator ReceiveMultipleClients([ValueSource("k_DeliveryParameters")] |
305 | 266 |
|
306 | 267 | yield return null; |
307 | 268 | } |
| 269 | + |
| 270 | + // Check that we get disconnected when overflowing the reliable send queue. |
| 271 | + [UnityTest] |
| 272 | + public IEnumerator DisconnectOnReliableSendQueueOverflow() |
| 273 | + { |
| 274 | + InitializeTransport(out m_Server, out m_ServerEvents); |
| 275 | + InitializeTransport(out m_Client1, out m_Client1Events); |
| 276 | + |
| 277 | + m_Server.StartServer(); |
| 278 | + m_Client1.StartClient(); |
| 279 | + |
| 280 | + yield return WaitForNetworkEvent(NetworkEvent.Connect, m_Client1Events); |
| 281 | + |
| 282 | + m_Server.Shutdown(); |
| 283 | + |
| 284 | + var numSends = (UnityTransport.InitialMaxSendQueueSize / 1024) + 1; |
| 285 | + |
| 286 | + for (int i = 0; i < numSends; i++) |
| 287 | + { |
| 288 | + var payload = new ArraySegment<byte>(new byte[1024]); |
| 289 | + m_Client1.Send(m_Client1.ServerClientId, payload, NetworkDelivery.Reliable); |
| 290 | + } |
| 291 | + |
| 292 | + LogAssert.Expect(LogType.Error, "Couldn't add payload of size 1024 to reliable send queue. " + |
| 293 | + $"Closing connection {m_Client1.ServerClientId} as reliability guarantees can't be maintained. " + |
| 294 | + $"Perhaps 'Max Send Queue Size' ({UnityTransport.InitialMaxSendQueueSize}) is too small for workload."); |
| 295 | + |
| 296 | + Assert.AreEqual(2, m_Client1Events.Count); |
| 297 | + Assert.AreEqual(NetworkEvent.Disconnect, m_Client1Events[1].Type); |
| 298 | + |
| 299 | + yield return null; |
| 300 | + } |
| 301 | + |
| 302 | + // Check that it's fine to overflow the unreliable send queue (traffic is flushed on overflow). |
| 303 | + [UnityTest] |
| 304 | + public IEnumerator SendCompletesOnUnreliableSendQueueOverflow() |
| 305 | + { |
| 306 | + InitializeTransport(out m_Server, out m_ServerEvents); |
| 307 | + InitializeTransport(out m_Client1, out m_Client1Events); |
| 308 | + |
| 309 | + m_Server.StartServer(); |
| 310 | + m_Client1.StartClient(); |
| 311 | + |
| 312 | + yield return WaitForNetworkEvent(NetworkEvent.Connect, m_Client1Events); |
| 313 | + |
| 314 | + var numSends = (UnityTransport.InitialMaxSendQueueSize / 1024) + 1; |
| 315 | + |
| 316 | + for (int i = 0; i < numSends; i++) |
| 317 | + { |
| 318 | + var payload = new ArraySegment<byte>(new byte[1024]); |
| 319 | + m_Client1.Send(m_Client1.ServerClientId, payload, NetworkDelivery.Unreliable); |
| 320 | + } |
| 321 | + |
| 322 | + // Manually wait. This ends up generating quite a bit of packets and it might take a |
| 323 | + // while for everything to make it to the server. |
| 324 | + yield return new WaitForSeconds(numSends * 0.02f); |
| 325 | + |
| 326 | + // Extra event is the connect event. |
| 327 | + Assert.AreEqual(numSends + 1, m_ServerEvents.Count); |
| 328 | + |
| 329 | + for (int i = 1; i <= numSends; i++) |
| 330 | + { |
| 331 | + Assert.AreEqual(NetworkEvent.Data, m_ServerEvents[i].Type); |
| 332 | + Assert.AreEqual(1024, m_ServerEvents[i].Data.Count); |
| 333 | + } |
| 334 | + |
| 335 | + yield return null; |
| 336 | + } |
308 | 337 | } |
309 | 338 | } |
310 | 339 | #endif |
0 commit comments