mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
NetworkServerTests: MaxMessageSize + 1
This commit is contained in:
parent
4703c5e939
commit
75b17b9a8d
@ -15,6 +15,9 @@ struct VariableSizedMessage : NetworkMessage
|
||||
public byte[] payload;
|
||||
// so payload := size - 4
|
||||
// then the message is exactly maxed size.
|
||||
//
|
||||
// NOTE: we have a LargerMaxMessageSize test which guarantees that
|
||||
// variablesized + 1 is exactly transport.max + 1
|
||||
public VariableSizedMessage(int size) => payload = new byte[size - 4];
|
||||
}
|
||||
|
||||
@ -377,6 +380,29 @@ public void Send_ClientToServerMessage_MaxMessageSize()
|
||||
Assert.That(called, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
// guarantee that exactly max message size + 1 doesn't work anymore
|
||||
[Test]
|
||||
public void Send_ClientToServerMessage_LargerThanMaxMessageSize()
|
||||
{
|
||||
// register a message handler
|
||||
int called = 0;
|
||||
NetworkServer.RegisterHandler<VariableSizedMessage>((conn, msg) => ++called, false);
|
||||
|
||||
// listen & connect a client
|
||||
NetworkServer.Listen(1);
|
||||
ConnectClientBlocking(out _);
|
||||
|
||||
// send message & process
|
||||
int transportMax = transport.GetMaxPacketSize(Channels.Reliable);
|
||||
int messageMax = transportMax - MessagePacking.HeaderSize;
|
||||
LogAssert.Expect(LogType.Error, $"NetworkConnection.ValidatePacketSize: cannot send packet larger than {transportMax} bytes, was {transportMax + 1} bytes");
|
||||
NetworkClient.Send(new VariableSizedMessage(messageMax + 1));
|
||||
ProcessMessages();
|
||||
|
||||
// should be too big to send
|
||||
Assert.That(called, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
// transport recommends a max batch size.
|
||||
// but we support up to max packet size.
|
||||
// for example, with KCP it makes sense to always send MTU sized batches.
|
||||
|
Loading…
Reference in New Issue
Block a user