NetworkServerTest: reuse MessagePacking.MaxMessageSize

This commit is contained in:
vis2k 2021-06-18 19:34:42 +08:00
parent 6ba6543278
commit 5644611d5d

View File

@ -370,12 +370,9 @@ public void Send_ClientToServerMessage_MaxMessageSize()
NetworkServer.Listen(1);
ConnectClientBlocking(out _);
// calculate max := transport.max - message header
int transportMax = transport.GetMaxPacketSize(Channels.Reliable);
int messageMax = transportMax - MessagePacking.HeaderSize;
// send message & process
NetworkClient.Send(new VariableSizedMessage(messageMax));
int max = MessagePacking.MaxMessageSize;
NetworkClient.Send(new VariableSizedMessage(max));
ProcessMessages();
// did it get through?
@ -394,12 +391,9 @@ public void Send_ServerToClientMessage_MaxMessageSize()
NetworkServer.Listen(1);
ConnectClientBlocking(out NetworkConnectionToClient connectionToClient);
// calculate max := transport.max - message header
int transportMax = transport.GetMaxPacketSize(Channels.Reliable);
int messageMax = transportMax - MessagePacking.HeaderSize;
// send message & process
connectionToClient.Send(new VariableSizedMessage(messageMax));
int max = MessagePacking.MaxMessageSize;
connectionToClient.Send(new VariableSizedMessage(max));
ProcessMessages();
// did it get through?
@ -419,10 +413,10 @@ public void Send_ClientToServerMessage_LargerThanMaxMessageSize()
ConnectClientBlocking(out _);
// calculate max := transport.max - message header
int transportMax = transport.GetMaxPacketSize(Channels.Reliable);
int messageMax = transportMax - MessagePacking.HeaderSize;
// send message & process
int transportMax = transport.GetMaxPacketSize(Channels.Reliable);
int messageMax = MessagePacking.MaxMessageSize;
LogAssert.Expect(LogType.Error, $"NetworkConnection.ValidatePacketSize: cannot send packet larger than {transportMax} bytes, was {transportMax + 1} bytes");
NetworkClient.Send(new VariableSizedMessage(messageMax + 1));
ProcessMessages();
@ -443,11 +437,9 @@ public void Send_ServerToClientMessage_LargerThanMaxMessageSize()
NetworkServer.Listen(1);
ConnectClientBlocking(out NetworkConnectionToClient connectionToClient);
// calculate max := transport.max - message header
int transportMax = transport.GetMaxPacketSize(Channels.Reliable);
int messageMax = transportMax - MessagePacking.HeaderSize;
// send message & process
int transportMax = transport.GetMaxPacketSize(Channels.Reliable);
int messageMax = MessagePacking.MaxMessageSize;
LogAssert.Expect(LogType.Error, $"NetworkConnection.ValidatePacketSize: cannot send packet larger than {transportMax} bytes, was {transportMax + 1} bytes");
connectionToClient.Send(new VariableSizedMessage(messageMax + 1));
ProcessMessages();