Skip to content

fix: update universal rpc tests revert spawnmany timeout #3168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 @@ -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