Skip to content

Commit 2cb2d84

Browse files
test update
Added some additional script to ignore anything that is not converted to run against the CMB server or any test that is configured to use a client-server network topology. Added OneTimeSetup to all non-NetcodeIntegrationTest derived tests that will also ignore the test until it is reviewed and determined it should be converted over or we do not need to run the test again since it will have already run multiple times on multiple platforms.
1 parent 1a4db66 commit 2cb2d84

35 files changed

+297
-88
lines changed

com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTest.cs

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,27 @@ public static void DeregisterNetworkObject(ulong localClientId, ulong networkObj
9696
}
9797
}
9898

99+
private int GetTotalClients()
100+
{
101+
if (m_DistributedAuthority)
102+
{
103+
// If not connecting to a CMB service then we are using a DAHost and we add 1 to this count.
104+
return !UseCMBService() && m_UseHost ? m_NumberOfClients + 1 : m_NumberOfClients;
105+
}
106+
else
107+
{
108+
// If using a host then we add one to this count.
109+
return m_UseHost ? m_NumberOfClients + 1 : m_NumberOfClients;
110+
}
111+
}
112+
99113
/// <summary>
100114
/// Total number of clients that should be connected at any point during a test.
101115
/// </summary>
102116
/// <remarks>
103117
/// When using the CMB Service, we ignore if <see cref="m_UseHost"/> is true.
104118
/// </remarks>
105-
protected int TotalClients => m_UseHost && !UseCMBService() ? m_NumberOfClients + 1 : m_NumberOfClients;
119+
protected int TotalClients => GetTotalClients();
106120

107121
protected const uint k_DefaultTickRate = 30;
108122

@@ -212,7 +226,7 @@ protected NetworkManager GetNonAuthorityNetworkManager()
212226
protected Dictionary<ulong, Dictionary<ulong, NetworkObject>> m_PlayerNetworkObjects = new Dictionary<ulong, Dictionary<ulong, NetworkObject>>();
213227

214228
protected bool m_UseHost = true;
215-
protected bool m_DistributedAuthority;
229+
protected bool m_DistributedAuthority => m_NetworkTopologyType == NetworkTopologyTypes.DistributedAuthority;
216230
protected NetworkTopologyTypes m_NetworkTopologyType = NetworkTopologyTypes.ClientServer;
217231

218232
/// <summary>
@@ -233,14 +247,14 @@ protected NetworkManager GetNonAuthorityNetworkManager()
233247
/// check the environment variable once per test set.
234248
/// </remarks>
235249
/// <returns>true/false</returns>
236-
private bool UseCMBServiceEnviromentVariableSet()
250+
private bool GetServiceEnviromentVariable()
237251
{
238252
if (!m_UseCmbServiceEnv && m_UseCmbServiceEnvString == null)
239253
{
240254
var useCmbService = Environment.GetEnvironmentVariable("USE_CMB_SERVICE") ?? "false";
241255
if (bool.TryParse(useCmbService.ToLower(), out bool isTrue))
242256
{
243-
m_UseCmbService = isTrue;
257+
m_UseCmbServiceEnv = isTrue;
244258
}
245259
else
246260
{
@@ -261,7 +275,7 @@ protected virtual bool UseCMBService()
261275
#if USE_CMB_SERVICE
262276
return true;
263277
#else
264-
return UseCMBServiceEnviromentVariableSet();
278+
return m_UseCmbService;
265279
#endif
266280
}
267281

@@ -408,6 +422,24 @@ protected virtual void OnOneTimeSetup()
408422

409423
[OneTimeSetUp]
410424
public void OneTimeSetup()
425+
{
426+
// Only For CMB Server Tests:
427+
// If the environment variable is set (i.e. doing a CMB server run) but UseCMBservice returns false, then ignore the test.
428+
// Note: This will prevent us from re-running all of the non-DA integration tests that have already run multiple times on
429+
// multiple platforms
430+
if (GetServiceEnviromentVariable() && !UseCMBService())
431+
{
432+
Assert.Ignore("[CMB-Server Test Run] Skipping non-distributed authority test.");
433+
return;
434+
}
435+
else
436+
{
437+
// Otherwise, continue with the test
438+
InternalOnOneTimeSetup();
439+
}
440+
}
441+
442+
private void InternalOnOneTimeSetup()
411443
{
412444
Application.runInBackground = true;
413445
m_NumberOfClients = NumberOfClients;
@@ -515,7 +547,6 @@ public IEnumerator SetUp()
515547

516548
}
517549
}
518-
519550
VerboseDebug($"Exiting {nameof(SetUp)}");
520551
}
521552

@@ -1983,23 +2014,45 @@ public NetcodeIntegrationTest(HostOrServer hostOrServer)
19832014
InitializeTestConfiguration(m_NetworkTopologyType, hostOrServer);
19842015
}
19852016

2017+
/// <summary>
2018+
/// Override this virtual method to execute script that runs before the base class constructor has finished executing.<br />
2019+
/// </summary>
2020+
/// <remarks>
2021+
/// ***NOTE***
2022+
/// When this method is invoked there will have been no properties set (i.e. nothing is configured). <br />
2023+
/// Primarily this is to set things like environemnt variables or other more external configurations that could
2024+
/// determine how the <see cref="NetcodeIntegrationTest"/> is configured.
2025+
/// </remarks>
2026+
protected virtual void OnPreInitializeConfiguration()
2027+
{
2028+
}
2029+
19862030
private void InitializeTestConfiguration(NetworkTopologyTypes networkTopologyType, HostOrServer? hostOrServer)
19872031
{
1988-
if (!hostOrServer.HasValue)
1989-
{
1990-
// Always default to hosting, set the type of host based on the topology type
1991-
hostOrServer = networkTopologyType == NetworkTopologyTypes.DistributedAuthority ? HostOrServer.DAHost : HostOrServer.Host;
1992-
}
2032+
OnPreInitializeConfiguration();
19932033

19942034
NetworkMessageManager.EnableMessageOrderConsoleLog = false;
19952035

2036+
// Set m_NetworkTopologyType first because m_DistributedAuthority is calculated from it.
19962037
m_NetworkTopologyType = networkTopologyType;
1997-
m_DistributedAuthority = m_NetworkTopologyType == NetworkTopologyTypes.DistributedAuthority;
2038+
2039+
if (!hostOrServer.HasValue)
2040+
{
2041+
// Always default to hosting, set the type of host based on the topology type.
2042+
// Note: For m_DistributedAuthority to be true, the m_NetworkTopologyType must be set to NetworkTopologyTypes.DistributedAuthority
2043+
hostOrServer = m_DistributedAuthority ? HostOrServer.DAHost : HostOrServer.Host;
2044+
}
19982045
m_UseHost = hostOrServer == HostOrServer.Host || hostOrServer == HostOrServer.DAHost;
19992046

2000-
if (UseCMBService())
2047+
// If we are using a distributed authority network topology and the environment variable
2048+
// to use the CMBService is set, then perform the m_UseCmbService check.
2049+
if (m_DistributedAuthority && GetServiceEnviromentVariable())
20012050
{
2002-
m_UseCmbService = m_DistributedAuthority && hostOrServer == HostOrServer.DAHost;
2051+
m_UseCmbService = hostOrServer == HostOrServer.DAHost;
2052+
// In the event UseCMBService is overridden, we apply the value returned.
2053+
// If it is, then whatever UseCMBService returns is the setting for m_UseCmbService.
2054+
// If it is not, then it will return whatever m_UseCmbService's setting is from the above check.
2055+
m_UseCmbService = UseCMBService();
20032056
}
20042057
}
20052058

com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,18 @@ public static void RegisterHandlers(NetworkManager networkManager, bool serverSi
172172
}
173173
}
174174

175+
/// <summary>
176+
/// Use for non <see cref="NetcodeIntegrationTest"/> derived integration tests to automatically ignore the
177+
/// test is the USE_CMB_SERVICE is set.
178+
/// </summary>
179+
internal static void IgnoreIfServiceEnviromentVariableSet()
180+
{
181+
if (bool.TryParse(Environment.GetEnvironmentVariable("USE_CMB_SERVICE") ?? "false", out bool isTrue) ? isTrue : false)
182+
{
183+
Assert.Ignore("[CMB-Server Test Run] Skipping non-distributed authority test.");
184+
}
185+
}
186+
175187
private static readonly string k_TransportHost = GetAddressToBind();
176188
private static readonly ushort k_TransportPort = GetPortToBind();
177189

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ internal class ClientOnlyConnectionTests
1515
private bool m_WasDisconnected;
1616
private TimeoutHelper m_TimeoutHelper;
1717

18+
[OneTimeSetUp]
19+
public void OneTimeSetup()
20+
{
21+
// TODO: [CmbServiceTests] if this test is deemed needed to test against the CMB server then update this test.
22+
NetcodeIntegrationTestHelpers.IgnoreIfServiceEnviromentVariableSet();
23+
}
24+
1825
[SetUp]
1926
public void Setup()
2027
{

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using NUnit.Framework;
2+
using Unity.Netcode.TestHelpers.Runtime;
23
using Unity.Netcode.Transports.UTP;
34
using UnityEngine;
45
using UnityEngine.TestTools;
@@ -8,6 +9,13 @@ namespace Unity.Netcode.RuntimeTests
89
{
910
internal class NestedNetworkManagerTests
1011
{
12+
[OneTimeSetUp]
13+
public void OneTimeSetup()
14+
{
15+
// TODO: [CmbServiceTests] if this test is deemed needed to test against the CMB server then update this test.
16+
NetcodeIntegrationTestHelpers.IgnoreIfServiceEnviromentVariableSet();
17+
}
18+
1119
[Test]
1220
public void CheckNestedNetworkManager()
1321
{

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ internal class NetworkManagerEventsTests
1717
private bool m_Instantiated;
1818
private bool m_Destroyed;
1919

20+
[OneTimeSetUp]
21+
public void OneTimeSetup()
22+
{
23+
// TODO: [CmbServiceTests] if this test is deemed needed to test against the CMB server then update this test.
24+
NetcodeIntegrationTestHelpers.IgnoreIfServiceEnviromentVariableSet();
25+
}
26+
2027
/// <summary>
2128
/// Validates the <see cref="NetworkManager.OnInstantiated"/> and <see cref="NetworkManager.OnDestroying"/> event notifications
2229
/// </summary>

com.unity.netcode.gameobjects/Tests/Runtime/Prefabs/NetworkPrefabHandlerTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ namespace Unity.Netcode.RuntimeTests
1616
/// </summary>
1717
internal class NetworkPrefabHandlerTests
1818
{
19+
[OneTimeSetUp]
20+
public void OneTimeSetup()
21+
{
22+
// TODO: [CmbServiceTests] if this test is deemed needed to test against the CMB server then update this test.
23+
NetcodeIntegrationTestHelpers.IgnoreIfServiceEnviromentVariableSet();
24+
}
1925

2026
private const string k_TestPrefabObjectName = "NetworkPrefabTestObject";
2127
private uint m_ObjectId = 1;
@@ -28,6 +34,8 @@ private GameObject MakeValidNetworkPrefab()
2834
return validPrefab.gameObject;
2935
}
3036

37+
38+
3139
/// <summary>
3240
/// Tests the NetwokConfig NetworkPrefabsList initialization during NetworkManager's Init method to make sure that
3341
/// it will still initialize but remove the invalid prefabs

com.unity.netcode.gameobjects/Tests/Runtime/Profiling/NetworkVariableNameTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ internal sealed class NetworkVariableNameTests
88
{
99
private NetworkVariableNameComponent m_NetworkVariableNameComponent;
1010

11+
[OneTimeSetUp]
12+
public void OneTimeSetup()
13+
{
14+
// TODO: [CmbServiceTests] if this test is deemed needed to test against the CMB server then update this test.
15+
NetcodeIntegrationTestHelpers.IgnoreIfServiceEnviromentVariableSet();
16+
}
17+
1118
[SetUp]
1219
public void SetUp()
1320
{

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ namespace Unity.Netcode.RuntimeTests
1515
/// </summary>
1616
internal class RpcQueueTests
1717
{
18+
[OneTimeSetUp]
19+
public void OneTimeSetup()
20+
{
21+
// TODO: [CmbServiceTests] if this test is deemed needed to test against the CMB server then update this test.
22+
NetcodeIntegrationTestHelpers.IgnoreIfServiceEnviromentVariableSet();
23+
}
24+
1825
[SetUp]
1926
public void Setup()
2027
{

com.unity.netcode.gameobjects/Tests/Runtime/Serialization/NetworkBehaviourReferenceTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ namespace Unity.Netcode.RuntimeTests
1515
/// </summary>
1616
internal class NetworkBehaviourReferenceTests : IDisposable
1717
{
18+
[OneTimeSetUp]
19+
public void OneTimeSetup()
20+
{
21+
// TODO: [CmbServiceTests] if this test is deemed needed to test against the CMB server then update this test.
22+
NetcodeIntegrationTestHelpers.IgnoreIfServiceEnviromentVariableSet();
23+
}
24+
1825
private class TestNetworkBehaviour : NetworkBehaviour
1926
{
2027
public static bool ReceivedRPC;

com.unity.netcode.gameobjects/Tests/Runtime/Serialization/NetworkObjectReferenceTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ namespace Unity.Netcode.RuntimeTests
1717
/// </summary>
1818
internal class NetworkObjectReferenceTests : IDisposable
1919
{
20+
[OneTimeSetUp]
21+
public void OneTimeSetup()
22+
{
23+
// TODO: [CmbServiceTests] if this test is deemed needed to test against the CMB server then update this test.
24+
NetcodeIntegrationTestHelpers.IgnoreIfServiceEnviromentVariableSet();
25+
}
26+
2027
private class TestNetworkBehaviour : NetworkBehaviour
2128
{
2229
public static bool ReceivedRPC;

0 commit comments

Comments
 (0)