From 75b17b9a8d3c0950c2d1f8f99b352a741a568526 Mon Sep 17 00:00:00 2001 From: vis2k Date: Fri, 18 Jun 2021 13:56:27 +0800 Subject: [PATCH] NetworkServerTests: MaxMessageSize + 1 --- .../Mirror/Tests/Editor/NetworkServerTest.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs index 82517f218..69b07bdf5 100644 --- a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs +++ b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs @@ -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((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.