Skip to content

Commit 38a4a92

Browse files
feat: increase hybrid prefab test coverage (#4172)
* test: run hybrid test cases over the unified transport N4E worlds and UnifiedNetcodeTransport only start when at least one hybrid prefab is registered. Player prefabs are never hybrid, so a UnifiedHost or UnifiedServer test case that spawns nothing but players silently ran as plain NGO. CreateServerAndClients now registers a UnifiedSessionPrefab when a hybrid test case registered no hybrid prefab of its own. * test: opt existing integration tests into hybrid prefab mode Adds UnifiedHost/UnifiedServer fixtures and the UseUnifiedTests opt-in to 25 fixtures covering RPCs, NetworkVariables and collections, connection approval, spawn/despawn, ownership, late-join synchronization and NGO parenting of hybrid objects. Ghosts spawn from a snapshot, later than NGO's spawn message, so tests that read SpawnedObjects immediately after a spawn or a late join now wait with WaitForSpawnedOnAllOrTimeOut. ComponentControllerTests' predicates were missing a continue and threw instead of waiting. RpcTests, RpcTypeSerializationTests and ClientApprovalDenied gain explicit Host/Server fixture arguments: NUnit drops a bare [TestFixture] when the class also has parameterized fixtures. NetworkObjectDeserializationFailure is ignored for hybrid prefabs: removing a prefab from one client's NetworkConfig does not unregister its ghost prefab, which all worlds in the process share. * test: run NetworkBehaviourUpdaterTests cases in one session per mode The fixture was expanded into 36 [TestFixture]s (mode x client count x NetVar combination), each starting its own session for both of its two test cases. It now has one fixture per HostOrServer mode, and a single test that walks the NetVar combinations and spawn counts in arrays, adding a client between passes and despawning each case's objects before the next. Failure messages name the case. The 1 and 2 client passes now include a late-joined client, where every case previously ran against a freshly started session. * test: loop NetworkVariableCollectionsChangingTests over its collection types The collection type only selects which helper component the prefab carries, so it no longer needs its own fixture. Both prefabs are registered up front and each test runs List then Dictionary in one session, despawning the instance from its current authority between them. Failure messages name the collection type. 10 fixtures become 5. * style: comment verbosity pass
1 parent 81b9151 commit 38a4a92

26 files changed

Lines changed: 475 additions & 169 deletions

‎com.unity.netcode.gameobjects/Tests/Runtime/ComponentControllerTests.cs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,21 @@ namespace Unity.Netcode.RuntimeTests
1212
[TestFixture(HostOrServer.Host)]
1313
[TestFixture(HostOrServer.Server)]
1414
[TestFixture(HostOrServer.DAHost)]
15+
#if UNIFIED_NETCODE
16+
[TestFixture(HostOrServer.UnifiedHost)]
17+
[TestFixture(HostOrServer.UnifiedServer)]
18+
#endif
1519
internal class ComponentControllerTests : NetcodeIntegrationTest
1620
{
1721
protected override int NumberOfClients => 2;
1822

23+
#if UNIFIED_NETCODE
24+
protected override bool UseUnifiedTests()
25+
{
26+
return true;
27+
}
28+
#endif
29+
1930
private StringBuilder m_ErrorLog = new StringBuilder();
2031
private GameObject m_TestPrefab;
2132

@@ -113,6 +124,7 @@ private bool AllComponentStatesMatch()
113124
if (!networkManager.SpawnManager.SpawnedObjects.ContainsKey(m_AuthorityController.NetworkObjectId))
114125
{
115126
m_ErrorLog.AppendLine($"[Client-{networkManager.LocalClientId}] Does not have a spawned instance of {m_AuthorityController.name}!");
127+
continue;
116128
}
117129
var controller = networkManager.SpawnManager.SpawnedObjects[m_AuthorityController.NetworkObjectId].GetComponent<ComponentController>();
118130
ControllerStateMatches(controller);
@@ -128,6 +140,7 @@ private bool AllComponentStatesAreCorrect(bool isEnabled)
128140
if (!networkManager.SpawnManager.SpawnedObjects.ContainsKey(m_AuthorityController.NetworkObjectId))
129141
{
130142
m_ErrorLog.AppendLine($"[Client-{networkManager.LocalClientId}] Does not have a spawned instance of {m_AuthorityController.name}!");
143+
continue;
131144
}
132145
var controller = networkManager.SpawnManager.SpawnedObjects[m_AuthorityController.NetworkObjectId].GetComponent<ComponentController>();
133146
for (int i = 0; i < controller.ValidComponents.Count; i++)

‎com.unity.netcode.gameobjects/Tests/Runtime/Connection/ClientApprovalDenied.cs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,23 @@
77

88
namespace Unity.Netcode.RuntimeTests
99
{
10+
[TestFixture(HostOrServer.Host)]
11+
#if UNIFIED_NETCODE
12+
[TestFixture(HostOrServer.UnifiedHost)]
13+
#endif
1014
internal class ClientApprovalDenied : NetcodeIntegrationTest
1115
{
1216
protected override int NumberOfClients => 2;
17+
18+
public ClientApprovalDenied(HostOrServer hostOrServer) : base(hostOrServer) { }
19+
20+
#if UNIFIED_NETCODE
21+
protected override bool UseUnifiedTests()
22+
{
23+
return true;
24+
}
25+
#endif
26+
1327
private bool m_ApproveConnection = true;
1428
private ulong m_PendingClientId = 0;
1529
private ulong m_DisconnectedClientId = 0;

‎com.unity.netcode.gameobjects/Tests/Runtime/Connection/ConnectionApproval.cs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ namespace Unity.Netcode.RuntimeTests
1313
[TestFixture(PlayerCreation.PrefabHash)]
1414
[TestFixture(PlayerCreation.NoPlayer)]
1515
[TestFixture(PlayerCreation.FailValidation)]
16+
#if UNIFIED_NETCODE
17+
[TestFixture(PlayerCreation.Prefab, HostOrServer.UnifiedHost)]
18+
[TestFixture(PlayerCreation.PrefabHash, HostOrServer.UnifiedHost)]
19+
[TestFixture(PlayerCreation.NoPlayer, HostOrServer.UnifiedHost)]
20+
[TestFixture(PlayerCreation.FailValidation, HostOrServer.UnifiedHost)]
21+
#endif
1622
internal class ConnectionApprovalTests : IntegrationTestWithApproximation
1723
{
1824
private const string k_InvalidToken = "Invalid validation token!";
@@ -36,6 +42,18 @@ public ConnectionApprovalTests(PlayerCreation playerCreation)
3642
m_PlayerCreation = playerCreation;
3743
}
3844

45+
#if UNIFIED_NETCODE
46+
public ConnectionApprovalTests(PlayerCreation playerCreation, HostOrServer hostOrServer) : base(hostOrServer)
47+
{
48+
m_PlayerCreation = playerCreation;
49+
}
50+
51+
protected override bool UseUnifiedTests()
52+
{
53+
return true;
54+
}
55+
#endif
56+
3957
protected override int NumberOfClients => 1;
4058

4159
private string m_ValidationToken;

‎com.unity.netcode.gameobjects/Tests/Runtime/Connection/ConnectionApprovalTimeoutTests.cs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ namespace Unity.Netcode.RuntimeTests
99
{
1010
[TestFixture(ApprovalTimedOutTypes.ServerDoesNotRespond)]
1111
[TestFixture(ApprovalTimedOutTypes.ClientDoesNotRequest)]
12+
#if UNIFIED_NETCODE
13+
[TestFixture(ApprovalTimedOutTypes.ServerDoesNotRespond, HostOrServer.UnifiedHost)]
14+
[TestFixture(ApprovalTimedOutTypes.ClientDoesNotRequest, HostOrServer.UnifiedHost)]
15+
#endif
1216
internal class ConnectionApprovalTimeoutTests : NetcodeIntegrationTest
1317
{
1418
protected override int NumberOfClients => 1;
@@ -26,6 +30,18 @@ public ConnectionApprovalTimeoutTests(ApprovalTimedOutTypes approvalFailureType)
2630
m_ApprovalFailureType = approvalFailureType;
2731
}
2832

33+
#if UNIFIED_NETCODE
34+
public ConnectionApprovalTimeoutTests(ApprovalTimedOutTypes approvalFailureType, HostOrServer hostOrServer) : base(hostOrServer)
35+
{
36+
m_ApprovalFailureType = approvalFailureType;
37+
}
38+
39+
protected override bool UseUnifiedTests()
40+
{
41+
return true;
42+
}
43+
#endif
44+
2945
// Must be >= 5 since this is an int value and the test waits for timeout - 1 to try to verify it doesn't
3046
// time out early
3147
private const int k_TestTimeoutPeriod = 3;

‎com.unity.netcode.gameobjects/Tests/Runtime/Messaging/MessageReceiveAllocationTests.cs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,20 @@ public void NotMeRpc()
2323

2424
[TestFixture(HostOrServer.Host)]
2525
[TestFixture(HostOrServer.DAHost)]
26+
#if UNIFIED_NETCODE
27+
[TestFixture(HostOrServer.UnifiedHost)]
28+
#endif
2629
internal class MessageReceiveAllocationTests : NetcodeIntegrationTest
2730
{
2831
protected override int NumberOfClients => 1;
2932

33+
#if UNIFIED_NETCODE
34+
protected override bool UseUnifiedTests()
35+
{
36+
return true;
37+
}
38+
#endif
39+
3040
public MessageReceiveAllocationTests(HostOrServer hostOrServer) : base(hostOrServer) { }
3141

3242
private GameObject m_Prefab;

‎com.unity.netcode.gameobjects/Tests/Runtime/NetworkBehaviourPrePostSpawnTests.cs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,20 @@ namespace Unity.Netcode.RuntimeTests
88
{
99
[TestFixture(HostOrServer.Host)]
1010
[TestFixture(HostOrServer.DAHost)]
11+
#if UNIFIED_NETCODE
12+
[TestFixture(HostOrServer.UnifiedHost)]
13+
#endif
1114
internal class NetworkBehaviourPrePostSpawnTests : NetcodeIntegrationTest
1215
{
1316
protected override int NumberOfClients => 0;
1417

18+
#if UNIFIED_NETCODE
19+
protected override bool UseUnifiedTests()
20+
{
21+
return true;
22+
}
23+
#endif
24+
1525
// TODO: [CmbServiceTests] Adapt to run with the service
1626
protected override bool UseCMBService()
1727
{

0 commit comments

Comments
 (0)