Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ public struct SimulatorParameters
PacketDropRate = 0
};

internal uint DebugSimulatorRandomSeed { get; set; } = 0;

private struct PacketLossCache
{
public int PacketsReceived;
Expand Down Expand Up @@ -1322,7 +1324,8 @@ private void ConfigureSimulator()
maxPacketSize: NetworkParameterConstants.MTU,
packetDelayMs: DebugSimulator.PacketDelayMS,
packetJitterMs: DebugSimulator.PacketJitterMS,
packetDropPercentage: DebugSimulator.PacketDropRate
packetDropPercentage: DebugSimulator.PacketDropRate,
randomSeed: DebugSimulatorRandomSeed
#if UTP_TRANSPORT_2_0_ABOVE
, mode: ApplyMode.AllPackets
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public class PacketLossMetricsTests : NetcodeIntegrationTest
{
protected override int NumberOfClients => 1;
private readonly int m_PacketLossRate = 25;
private readonly int m_PacketLossRangeDelta = 5;
private readonly int m_PacketLossRangeDelta = 3;
private readonly int m_MessageSize = 200;

public PacketLossMetricsTests()
: base(HostOrServer.Server)
Expand All @@ -27,6 +28,12 @@ protected override void OnServerAndClientsCreated()
var clientTransport = (UnityTransport)m_ClientNetworkManagers[0].NetworkConfig.NetworkTransport;
clientTransport.SetDebugSimulatorParameters(0, 0, m_PacketLossRate);

// Determined through trial and error. With both UTP 1.2 and 2.0, this random seed
// results in an effective packet loss percentage between 22% and 28%. Future UTP
// updates may change the RNG call patterns and cause this test to fail, in which
// case the value should be modified again.
clientTransport.DebugSimulatorRandomSeed = 4;

base.OnServerAndClientsCreated();
}

Expand All @@ -39,8 +46,8 @@ public IEnumerator TrackPacketLossAsServer()

for (int i = 0; i < 1000; ++i)
{
using var writer = new FastBufferWriter(sizeof(byte), Allocator.Persistent);
writer.WriteByteSafe(42);
using var writer = new FastBufferWriter(m_MessageSize, Allocator.Persistent);
writer.WriteBytesSafe(new byte[m_MessageSize]);
m_ServerNetworkManager.CustomMessagingManager.SendNamedMessage("Test", m_ServerNetworkManager.ConnectedClientsIds, writer);
}

Expand All @@ -51,9 +58,6 @@ public IEnumerator TrackPacketLossAsServer()
}

[UnityTest]
#if UTP_TRANSPORT_2_0_ABOVE
[Ignore("Pending adjustment for UTP 2.0")]
#endif
public IEnumerator TrackPacketLossAsClient()
{
double packetLossRateMinRange = (m_PacketLossRate - m_PacketLossRangeDelta) / 100d;
Expand All @@ -65,8 +69,8 @@ public IEnumerator TrackPacketLossAsClient()

for (int i = 0; i < 1000; ++i)
{
using var writer = new FastBufferWriter(sizeof(byte), Allocator.Persistent);
writer.WriteByteSafe(42);
using var writer = new FastBufferWriter(m_MessageSize, Allocator.Persistent);
writer.WriteBytesSafe(new byte[m_MessageSize]);
m_ServerNetworkManager.CustomMessagingManager.SendNamedMessage("Test", m_ServerNetworkManager.ConnectedClientsIds, writer);
}

Expand Down