Skip to content

Commit

Permalink
fix: update universal rpc tests revert spawnmany timeout (#3168)
Browse files Browse the repository at this point in the history
* update

reverting the removal of the timeout.
making it actually 6 minutes.

* fix

Using the NGO v2. version of the UniversalRpcTestSendingWithGroupNotOverride and TestSendingWithGroupOverride tests.
  • Loading branch information
NoelStephensUnity authored Dec 12, 2024
1 parent a90b0f4 commit 5425071
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ protected override void OnServerAndClientsCreated()
}

[UnityTest]
// When this test fails it does so without an exception and will wait the default ~6 minutes
[Timeout(360000)]
public IEnumerator WhenManyObjectsAreSpawnedAtOnce_AllAreReceived()
{
for (int x = 0; x < k_SpawnedObjects; x++)
Expand Down
222 changes: 90 additions & 132 deletions com.unity.netcode.gameobjects/Tests/Runtime/UniversalRpcTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,7 @@ public IEnumerator TestSendingWithSingleNotOverride()

}

[Timeout(1200000)]
[TestFixture(HostOrServer.Host)]
[TestFixture(HostOrServer.Server)]
internal class UniversalRpcTestSendingWithGroupOverride : UniversalRpcTestsBase
Expand All @@ -1285,80 +1286,59 @@ public enum AllocationType
List
}

[UnityTest]
public IEnumerator TestSendingWithGroupOverride()
// Extending timeout since the added yield return causes this test to commonly timeout
[Test]
public void TestSendingWithGroupOverride(
[Values] SendTo defaultSendTo,
[ValueSource(nameof(RecipientGroups))] ulong[] recipient,
[Values(0u, 1u, 2u)] ulong objectOwner,
[Values(0u, 1u, 2u)] ulong sender,
[Values] AllocationType allocationType
)
{
var waitFor = new WaitForFixedUpdate();
foreach (var defaultSendTo in Enum.GetValues(typeof(SendTo)))
{
m_EnableVerboseDebug = true;
VerboseDebug($"Processing: {defaultSendTo}");
m_EnableVerboseDebug = false;
var sendMethodName = $"DefaultTo{defaultSendTo}AllowOverrideRpc";

foreach (var recipient in RecipientGroups)
{
for (ulong objectOwner = 0u; objectOwner <= 2u; ++objectOwner)
var senderObject = GetPlayerObject(objectOwner, sender);
BaseRpcTarget target = null;
switch (allocationType)
{
case AllocationType.Array:
target = senderObject.RpcTarget.Group(recipient, RpcTargetUse.Temp);
break;
case AllocationType.List:
target = senderObject.RpcTarget.Group(recipient.ToList(), RpcTargetUse.Temp);
break;
case AllocationType.NativeArray:
var arr = new NativeArray<ulong>(recipient, Allocator.Temp);
target = senderObject.RpcTarget.Group(arr, RpcTargetUse.Temp);
arr.Dispose();
break;
case AllocationType.NativeList:
// For some reason on 2020.3, calling list.AsArray() and passing that to the next function
// causes Allocator.Temp allocations to become invalid somehow. This is not an issue on later
// versions of Unity.
var list = new NativeList<ulong>(recipient.Length, Allocator.TempJob);
foreach (var id in recipient)
{
for (ulong sender = 0u; sender <= 2u; ++sender)
{
yield return waitFor;
foreach (var allocationType in Enum.GetValues(typeof(AllocationType)))
{
//if (++YieldCheck % YieldCycleCount == 0)
//{
// yield return null;
//}
OnInlineSetup();
var sendMethodName = $"DefaultTo{defaultSendTo}AllowOverrideRpc";

var senderObject = GetPlayerObject(objectOwner, sender);
BaseRpcTarget target = null;
switch (allocationType)
{
case AllocationType.Array:
target = senderObject.RpcTarget.Group(recipient, RpcTargetUse.Temp);
break;
case AllocationType.List:
target = senderObject.RpcTarget.Group(recipient.ToList(), RpcTargetUse.Temp);
break;
case AllocationType.NativeArray:
var arr = new NativeArray<ulong>(recipient, Allocator.Temp);
target = senderObject.RpcTarget.Group(arr, RpcTargetUse.Temp);
arr.Dispose();
break;
case AllocationType.NativeList:
// For some reason on 2020.3, calling list.AsArray() and passing that to the next function
// causes Allocator.Temp allocations to become invalid somehow. This is not an issue on later
// versions of Unity.
var list = new NativeList<ulong>(recipient.Length, Allocator.TempJob);
foreach (var id in recipient)
{
list.Add(id);
}

target = senderObject.RpcTarget.Group(list, RpcTargetUse.Temp);
list.Dispose();
break;
}

var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
sendMethod.Invoke(senderObject, new object[] { (RpcParams)target });

VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => recipient.Contains(c)).ToArray(), false);
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray());

// Pass some time to make sure that no other client ever receives this
TimeTravel(1f, 30);
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray());
OnInlineTearDown();
}
}
list.Add(id);
}
}
target = senderObject.RpcTarget.Group(list, RpcTargetUse.Temp);
list.Dispose();
break;
}
var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
sendMethod.Invoke(senderObject, new object[] { (RpcParams)target });

VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => recipient.Contains(c)).ToArray(), false);
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray());

// Pass some time to make sure that no other client ever receives this
TimeTravel(1f, 30);
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray());
}
}

[Timeout(1200000)]
[TestFixture(HostOrServer.Host)]
[TestFixture(HostOrServer.Server)]
internal class UniversalRpcTestSendingWithGroupNotOverride : UniversalRpcTestsBase
Expand All @@ -1384,78 +1364,56 @@ public enum AllocationType
List
}

[UnityTest]
public IEnumerator TestSendingWithGroupNotOverride()
// Extending timeout since the added yield return causes this test to commonly timeout
[Test]
public void TestSendingWithGroupNotOverride(
[Values] SendTo defaultSendTo,
[ValueSource(nameof(RecipientGroups))] ulong[] recipient,
[Values(0u, 1u, 2u)] ulong objectOwner,
[Values(0u, 1u, 2u)] ulong sender,
[Values] AllocationType allocationType
)
{
var waitFor = new WaitForFixedUpdate();
foreach (var defaultSendTo in Enum.GetValues(typeof(SendTo)))
var sendMethodName = $"DefaultTo{defaultSendTo}AllowOverrideRpc";

var senderObject = GetPlayerObject(objectOwner, sender);
BaseRpcTarget target = null;
switch (allocationType)
{
m_EnableVerboseDebug = true;
VerboseDebug($"Processing: {defaultSendTo}");
m_EnableVerboseDebug = false;
foreach (var recipient in RecipientGroups)
{
for (ulong objectOwner = 0u; objectOwner <= 2u; ++objectOwner)
case AllocationType.Array:
target = senderObject.RpcTarget.Not(recipient, RpcTargetUse.Temp);
break;
case AllocationType.List:
target = senderObject.RpcTarget.Not(recipient.ToList(), RpcTargetUse.Temp);
break;
case AllocationType.NativeArray:
var arr = new NativeArray<ulong>(recipient, Allocator.Temp);
target = senderObject.RpcTarget.Not(arr, RpcTargetUse.Temp);
arr.Dispose();
break;
case AllocationType.NativeList:
// For some reason on 2020.3, calling list.AsArray() and passing that to the next function
// causes Allocator.Temp allocations to become invalid somehow. This is not an issue on later
// versions of Unity.
var list = new NativeList<ulong>(recipient.Length, Allocator.TempJob);
foreach (var id in recipient)
{
for (ulong sender = 0u; sender <= 2u; ++sender)
{
yield return waitFor;

foreach (var allocationType in Enum.GetValues(typeof(AllocationType)))
{
//if (++YieldCheck % YieldCycleCount == 0)
//{
// yield return waitFor;
//}

OnInlineSetup();
var sendMethodName = $"DefaultTo{defaultSendTo}AllowOverrideRpc";

var senderObject = GetPlayerObject(objectOwner, sender);
BaseRpcTarget target = null;
switch (allocationType)
{
case AllocationType.Array:
target = senderObject.RpcTarget.Not(recipient, RpcTargetUse.Temp);
break;
case AllocationType.List:
target = senderObject.RpcTarget.Not(recipient.ToList(), RpcTargetUse.Temp);
break;
case AllocationType.NativeArray:
var arr = new NativeArray<ulong>(recipient, Allocator.Temp);
target = senderObject.RpcTarget.Not(arr, RpcTargetUse.Temp);
arr.Dispose();
break;
case AllocationType.NativeList:
// For some reason on 2020.3, calling list.AsArray() and passing that to the next function
// causes Allocator.Temp allocations to become invalid somehow. This is not an issue on later
// versions of Unity.
var list = new NativeList<ulong>(recipient.Length, Allocator.TempJob);
foreach (var id in recipient)
{
list.Add(id);
}
target = senderObject.RpcTarget.Not(list, RpcTargetUse.Temp);
list.Dispose();
break;
}
var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
sendMethod.Invoke(senderObject, new object[] { (RpcParams)target });

VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray(), false);
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient.Contains(c)).ToArray());

// Pass some time to make sure that no other client ever receives this
TimeTravel(1f, 30);
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient.Contains(c)).ToArray());
OnInlineTearDown();
}
}
list.Add(id);
}
}
target = senderObject.RpcTarget.Not(list, RpcTargetUse.Temp);
list.Dispose();
break;
}
}
var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
sendMethod.Invoke(senderObject, new object[] { (RpcParams)target });

VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray(), false);
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient.Contains(c)).ToArray());

// Pass some time to make sure that no other client ever receives this
TimeTravel(1f, 30);
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient.Contains(c)).ToArray());
}
}

[TestFixture(HostOrServer.Host)]
Expand Down

0 comments on commit 5425071

Please sign in to comment.