-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Peer): adding send buffer limit (#939)
* feat(Peer): adding send buffer limit stops send buffer getting too large (holding too many packets in memory at once) * tests
- Loading branch information
1 parent
aa8fe87
commit b4666cb
Showing
3 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
Assets/Tests/SocketLayer/AckSystem/AckSystemTest_BufferSize.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using NUnit.Framework; | ||
|
||
namespace Mirage.SocketLayer.Tests.AckSystemTests | ||
{ | ||
[Category("SocketLayer")] | ||
public class AckSystemTest_BufferSize : AckSystemTestBase | ||
{ | ||
[Test] | ||
public void ThrowsIfTooManyMessageAreSent() | ||
{ | ||
var time = new Time(); | ||
var config = new Config | ||
{ | ||
MaxReliablePacketsInSendBufferPerConnection = 50, | ||
SequenceSize = 8 | ||
}; | ||
var instance = new AckTestInstance | ||
{ | ||
connection = new SubIRawConnection() | ||
}; | ||
instance.ackSystem = new AckSystem(instance.connection, config, time, bufferPool); | ||
|
||
for (int i = 0; i < 50; i++) | ||
{ | ||
instance.ackSystem.SendReliable(createRandomData(i)); | ||
// update to send batch | ||
instance.ackSystem.Update(); | ||
} | ||
|
||
InvalidOperationException exception = Assert.Throws<InvalidOperationException>(() => | ||
{ | ||
instance.ackSystem.SendReliable(createRandomData(51)); | ||
instance.ackSystem.Update(); | ||
}); | ||
var expected = new InvalidOperationException($"Max packets in send buffer reached for {instance.connection}"); | ||
Assert.That(exception, Has.Message.EqualTo(expected.Message)); | ||
} | ||
|
||
[Test] | ||
public void ThrowIfRingBufferIsfull() | ||
{ | ||
var time = new Time(); | ||
var config = new Config | ||
{ | ||
MaxReliablePacketsInSendBufferPerConnection = 500, | ||
SequenceSize = 8 | ||
}; | ||
var instance = new AckTestInstance | ||
{ | ||
connection = new SubIRawConnection() | ||
}; | ||
instance.ackSystem = new AckSystem(instance.connection, config, time, bufferPool); | ||
|
||
for (int i = 0; i < 255; i++) | ||
{ | ||
instance.ackSystem.SendReliable(createRandomData(i)); | ||
// update to send batch | ||
instance.ackSystem.Update(); | ||
} | ||
|
||
InvalidOperationException exception = Assert.Throws<InvalidOperationException>(() => | ||
{ | ||
instance.ackSystem.SendReliable(createRandomData(0)); | ||
instance.ackSystem.Update(); | ||
}); | ||
var expected = new InvalidOperationException($"Sent queue is full for {instance.connection}"); | ||
Assert.That(exception, Has.Message.EqualTo(expected.Message)); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Tests/SocketLayer/AckSystem/AckSystemTest_BufferSize.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.