Skip to content

Commit 5425071

Browse files
fix: update universal rpc tests revert spawnmany timeout (#3168)
* update reverting the removal of the timeout. making it actually 6 minutes. * fix Using the NGO v2. version of the UniversalRpcTestSendingWithGroupNotOverride and TestSendingWithGroupOverride tests.
1 parent a90b0f4 commit 5425071

File tree

2 files changed

+92
-132
lines changed

2 files changed

+92
-132
lines changed

com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectSpawnManyObjectsTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ protected override void OnServerAndClientsCreated()
4747
}
4848

4949
[UnityTest]
50+
// When this test fails it does so without an exception and will wait the default ~6 minutes
51+
[Timeout(360000)]
5052
public IEnumerator WhenManyObjectsAreSpawnedAtOnce_AllAreReceived()
5153
{
5254
for (int x = 0; x < k_SpawnedObjects; x++)

com.unity.netcode.gameobjects/Tests/Runtime/UniversalRpcTests.cs

Lines changed: 90 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,7 @@ public IEnumerator TestSendingWithSingleNotOverride()
12601260

12611261
}
12621262

1263+
[Timeout(1200000)]
12631264
[TestFixture(HostOrServer.Host)]
12641265
[TestFixture(HostOrServer.Server)]
12651266
internal class UniversalRpcTestSendingWithGroupOverride : UniversalRpcTestsBase
@@ -1285,80 +1286,59 @@ public enum AllocationType
12851286
List
12861287
}
12871288

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

1298-
foreach (var recipient in RecipientGroups)
1299-
{
1300-
for (ulong objectOwner = 0u; objectOwner <= 2u; ++objectOwner)
1301+
var senderObject = GetPlayerObject(objectOwner, sender);
1302+
BaseRpcTarget target = null;
1303+
switch (allocationType)
1304+
{
1305+
case AllocationType.Array:
1306+
target = senderObject.RpcTarget.Group(recipient, RpcTargetUse.Temp);
1307+
break;
1308+
case AllocationType.List:
1309+
target = senderObject.RpcTarget.Group(recipient.ToList(), RpcTargetUse.Temp);
1310+
break;
1311+
case AllocationType.NativeArray:
1312+
var arr = new NativeArray<ulong>(recipient, Allocator.Temp);
1313+
target = senderObject.RpcTarget.Group(arr, RpcTargetUse.Temp);
1314+
arr.Dispose();
1315+
break;
1316+
case AllocationType.NativeList:
1317+
// For some reason on 2020.3, calling list.AsArray() and passing that to the next function
1318+
// causes Allocator.Temp allocations to become invalid somehow. This is not an issue on later
1319+
// versions of Unity.
1320+
var list = new NativeList<ulong>(recipient.Length, Allocator.TempJob);
1321+
foreach (var id in recipient)
13011322
{
1302-
for (ulong sender = 0u; sender <= 2u; ++sender)
1303-
{
1304-
yield return waitFor;
1305-
foreach (var allocationType in Enum.GetValues(typeof(AllocationType)))
1306-
{
1307-
//if (++YieldCheck % YieldCycleCount == 0)
1308-
//{
1309-
// yield return null;
1310-
//}
1311-
OnInlineSetup();
1312-
var sendMethodName = $"DefaultTo{defaultSendTo}AllowOverrideRpc";
1313-
1314-
var senderObject = GetPlayerObject(objectOwner, sender);
1315-
BaseRpcTarget target = null;
1316-
switch (allocationType)
1317-
{
1318-
case AllocationType.Array:
1319-
target = senderObject.RpcTarget.Group(recipient, RpcTargetUse.Temp);
1320-
break;
1321-
case AllocationType.List:
1322-
target = senderObject.RpcTarget.Group(recipient.ToList(), RpcTargetUse.Temp);
1323-
break;
1324-
case AllocationType.NativeArray:
1325-
var arr = new NativeArray<ulong>(recipient, Allocator.Temp);
1326-
target = senderObject.RpcTarget.Group(arr, RpcTargetUse.Temp);
1327-
arr.Dispose();
1328-
break;
1329-
case AllocationType.NativeList:
1330-
// For some reason on 2020.3, calling list.AsArray() and passing that to the next function
1331-
// causes Allocator.Temp allocations to become invalid somehow. This is not an issue on later
1332-
// versions of Unity.
1333-
var list = new NativeList<ulong>(recipient.Length, Allocator.TempJob);
1334-
foreach (var id in recipient)
1335-
{
1336-
list.Add(id);
1337-
}
1338-
1339-
target = senderObject.RpcTarget.Group(list, RpcTargetUse.Temp);
1340-
list.Dispose();
1341-
break;
1342-
}
1343-
1344-
var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
1345-
sendMethod.Invoke(senderObject, new object[] { (RpcParams)target });
1346-
1347-
VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => recipient.Contains(c)).ToArray(), false);
1348-
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray());
1349-
1350-
// Pass some time to make sure that no other client ever receives this
1351-
TimeTravel(1f, 30);
1352-
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray());
1353-
OnInlineTearDown();
1354-
}
1355-
}
1323+
list.Add(id);
13561324
}
1357-
}
1325+
target = senderObject.RpcTarget.Group(list, RpcTargetUse.Temp);
1326+
list.Dispose();
1327+
break;
13581328
}
1329+
var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
1330+
sendMethod.Invoke(senderObject, new object[] { (RpcParams)target });
1331+
1332+
VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => recipient.Contains(c)).ToArray(), false);
1333+
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray());
1334+
1335+
// Pass some time to make sure that no other client ever receives this
1336+
TimeTravel(1f, 30);
1337+
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray());
13591338
}
13601339
}
13611340

1341+
[Timeout(1200000)]
13621342
[TestFixture(HostOrServer.Host)]
13631343
[TestFixture(HostOrServer.Server)]
13641344
internal class UniversalRpcTestSendingWithGroupNotOverride : UniversalRpcTestsBase
@@ -1384,78 +1364,56 @@ public enum AllocationType
13841364
List
13851365
}
13861366

1387-
[UnityTest]
1388-
public IEnumerator TestSendingWithGroupNotOverride()
1367+
// Extending timeout since the added yield return causes this test to commonly timeout
1368+
[Test]
1369+
public void TestSendingWithGroupNotOverride(
1370+
[Values] SendTo defaultSendTo,
1371+
[ValueSource(nameof(RecipientGroups))] ulong[] recipient,
1372+
[Values(0u, 1u, 2u)] ulong objectOwner,
1373+
[Values(0u, 1u, 2u)] ulong sender,
1374+
[Values] AllocationType allocationType
1375+
)
13891376
{
1390-
var waitFor = new WaitForFixedUpdate();
1391-
foreach (var defaultSendTo in Enum.GetValues(typeof(SendTo)))
1377+
var sendMethodName = $"DefaultTo{defaultSendTo}AllowOverrideRpc";
1378+
1379+
var senderObject = GetPlayerObject(objectOwner, sender);
1380+
BaseRpcTarget target = null;
1381+
switch (allocationType)
13921382
{
1393-
m_EnableVerboseDebug = true;
1394-
VerboseDebug($"Processing: {defaultSendTo}");
1395-
m_EnableVerboseDebug = false;
1396-
foreach (var recipient in RecipientGroups)
1397-
{
1398-
for (ulong objectOwner = 0u; objectOwner <= 2u; ++objectOwner)
1383+
case AllocationType.Array:
1384+
target = senderObject.RpcTarget.Not(recipient, RpcTargetUse.Temp);
1385+
break;
1386+
case AllocationType.List:
1387+
target = senderObject.RpcTarget.Not(recipient.ToList(), RpcTargetUse.Temp);
1388+
break;
1389+
case AllocationType.NativeArray:
1390+
var arr = new NativeArray<ulong>(recipient, Allocator.Temp);
1391+
target = senderObject.RpcTarget.Not(arr, RpcTargetUse.Temp);
1392+
arr.Dispose();
1393+
break;
1394+
case AllocationType.NativeList:
1395+
// For some reason on 2020.3, calling list.AsArray() and passing that to the next function
1396+
// causes Allocator.Temp allocations to become invalid somehow. This is not an issue on later
1397+
// versions of Unity.
1398+
var list = new NativeList<ulong>(recipient.Length, Allocator.TempJob);
1399+
foreach (var id in recipient)
13991400
{
1400-
for (ulong sender = 0u; sender <= 2u; ++sender)
1401-
{
1402-
yield return waitFor;
1403-
1404-
foreach (var allocationType in Enum.GetValues(typeof(AllocationType)))
1405-
{
1406-
//if (++YieldCheck % YieldCycleCount == 0)
1407-
//{
1408-
// yield return waitFor;
1409-
//}
1410-
1411-
OnInlineSetup();
1412-
var sendMethodName = $"DefaultTo{defaultSendTo}AllowOverrideRpc";
1413-
1414-
var senderObject = GetPlayerObject(objectOwner, sender);
1415-
BaseRpcTarget target = null;
1416-
switch (allocationType)
1417-
{
1418-
case AllocationType.Array:
1419-
target = senderObject.RpcTarget.Not(recipient, RpcTargetUse.Temp);
1420-
break;
1421-
case AllocationType.List:
1422-
target = senderObject.RpcTarget.Not(recipient.ToList(), RpcTargetUse.Temp);
1423-
break;
1424-
case AllocationType.NativeArray:
1425-
var arr = new NativeArray<ulong>(recipient, Allocator.Temp);
1426-
target = senderObject.RpcTarget.Not(arr, RpcTargetUse.Temp);
1427-
arr.Dispose();
1428-
break;
1429-
case AllocationType.NativeList:
1430-
// For some reason on 2020.3, calling list.AsArray() and passing that to the next function
1431-
// causes Allocator.Temp allocations to become invalid somehow. This is not an issue on later
1432-
// versions of Unity.
1433-
var list = new NativeList<ulong>(recipient.Length, Allocator.TempJob);
1434-
foreach (var id in recipient)
1435-
{
1436-
list.Add(id);
1437-
}
1438-
target = senderObject.RpcTarget.Not(list, RpcTargetUse.Temp);
1439-
list.Dispose();
1440-
break;
1441-
}
1442-
var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
1443-
sendMethod.Invoke(senderObject, new object[] { (RpcParams)target });
1444-
1445-
VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray(), false);
1446-
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient.Contains(c)).ToArray());
1447-
1448-
// Pass some time to make sure that no other client ever receives this
1449-
TimeTravel(1f, 30);
1450-
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient.Contains(c)).ToArray());
1451-
OnInlineTearDown();
1452-
}
1453-
}
1401+
list.Add(id);
14541402
}
1455-
}
1403+
target = senderObject.RpcTarget.Not(list, RpcTargetUse.Temp);
1404+
list.Dispose();
1405+
break;
14561406
}
1457-
}
1407+
var sendMethod = senderObject.GetType().GetMethod(sendMethodName);
1408+
sendMethod.Invoke(senderObject, new object[] { (RpcParams)target });
1409+
1410+
VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray(), false);
1411+
VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient.Contains(c)).ToArray());
14581412

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

14611419
[TestFixture(HostOrServer.Host)]

0 commit comments

Comments
 (0)