Tests: MemoryTransport guarantees max message size just like a real transport would. Guarantees that even if Mirror tests have max message size issues, transport would catch it.

This commit is contained in:
vis2k 2021-06-18 15:55:52 +08:00
parent 0cce4962d2
commit d818b2d4aa

View File

@ -57,6 +57,15 @@ public override void ClientSend(ArraySegment<byte> segment, int channelId)
// only if client connected // only if client connected
if (clientConnected) if (clientConnected)
{ {
// a real transport fails for > max sized messages.
// mirror checks it, but let's guarantee that we catch > max
// sized message send attempts just like a real transport would.
// => helps to cover packet size issues i.e. for timestamp
// batching tests
int max = GetMaxPacketSize(channelId);
if (segment.Count > max)
throw new Exception($"MemoryTransport ClientSend of {segment.Count} bytes exceeds max of {max} bytes");
// copy segment data because it's only valid until return // copy segment data because it's only valid until return
byte[] data = new byte[segment.Count]; byte[] data = new byte[segment.Count];
Array.Copy(segment.Array, segment.Offset, data, 0, segment.Count); Array.Copy(segment.Array, segment.Offset, data, 0, segment.Count);
@ -120,6 +129,15 @@ public override void ServerSend(int connectionId, ArraySegment<byte> segment, in
// only if server is running and client is connected // only if server is running and client is connected
if (serverActive && clientConnected) if (serverActive && clientConnected)
{ {
// a real transport fails for > max sized messages.
// mirror checks it, but let's guarantee that we catch > max
// sized message send attempts just like a real transport would.
// => helps to cover packet size issues i.e. for timestamp
// batching tests
int max = GetMaxPacketSize(channelId);
if (segment.Count > max)
throw new Exception($"MemoryTransport ServerSend of {segment.Count} bytes exceeds max of {max} bytes");
// copy segment data because it's only valid until return // copy segment data because it's only valid until return
byte[] data = new byte[segment.Count]; byte[] data = new byte[segment.Count];
Array.Copy(segment.Array, segment.Offset, data, 0, segment.Count); Array.Copy(segment.Array, segment.Offset, data, 0, segment.Count);