Class NetcodeIntegrationTest
The default Netcode for GameObjects integration test helper class
Inherited Members
Namespace: Unity.Netcode.TestHelpers.Runtime
Assembly: Unity.Netcode.Runtime.Tests.dll
Syntax
public abstract class NetcodeIntegrationTest
Constructors
NetcodeIntegrationTest()
Default constructor
Declaration
public NetcodeIntegrationTest()
NetcodeIntegrationTest(NetworkTopologyTypes)
Overloaded constructor taking NetworkTopologyTypes as a parameter.
Declaration
public NetcodeIntegrationTest(NetworkTopologyTypes networkTopologyType)
Parameters
Type | Name | Description |
---|---|---|
NetworkTopologyTypes | networkTopologyType |
NetcodeIntegrationTest(NetworkTopologyTypes, HostOrServer)
Overloaded constructor taking NetworkTopologyTypes and NetcodeIntegrationTest.HostOrServer as parameters.
Declaration
public NetcodeIntegrationTest(NetworkTopologyTypes networkTopologyType, NetcodeIntegrationTest.HostOrServer hostOrServer)
Parameters
Type | Name | Description |
---|---|---|
NetworkTopologyTypes | networkTopologyType | |
NetcodeIntegrationTest.HostOrServer | hostOrServer |
NetcodeIntegrationTest(HostOrServer)
Optional Host or Server integration tests Constructor that allows you To break tests up as a host and a server. Example: Decorate your child derived class with TestFixture and then create a constructor at the child level. Don't forget to set your constructor public, else Unity will give you a hard to decipher error [TestFixture(HostOrServer.Host)] [TestFixture(HostOrServer.Server)] public class MyChildClass : NetcodeIntegrationTest { public MyChildClass(HostOrServer hostOrServer) : base(hostOrServer) }
Declaration
public NetcodeIntegrationTest(NetcodeIntegrationTest.HostOrServer hostOrServer)
Parameters
Type | Name | Description |
---|---|---|
NetcodeIntegrationTest.HostOrServer | hostOrServer | Specifies whether to run the test as a Host or Server configuration |
Fields
NetcodeLogAssert
Can be used to handle log assertions.
Declaration
public NetcodeLogAssert NetcodeLogAssert
Field Value
Type | Description |
---|---|
NetcodeLogAssert |
k_DefaultTickRate
Defines the default tick rate to use.
Declaration
protected const uint k_DefaultTickRate = 30
Field Value
Type | Description |
---|---|
uint |
k_DefaultTimeoutPeriod
Used to determine if a NetcodeIntegrationTest is currently running to determine how clients will load scenes
Declaration
protected const float k_DefaultTimeoutPeriod = 8
Field Value
Type | Description |
---|---|
float |
k_TickFrequency
Returns the default tick rate divided into one in order to get the tick frequency.
Declaration
protected const float k_TickFrequency = 0.033333335
Field Value
Type | Description |
---|---|
float |
m_ClientNetworkManagers
All the client NetworkManager instances instantiated and tracked within the current test
Declaration
protected NetworkManager[] m_ClientNetworkManagers
Field Value
Type | Description |
---|---|
NetworkManager[] |
m_CreateServerFirst
Set this to false to create the clients first.
Note: If you are using scene placed NetworkObjects or doing any form of scene testing and
get prefab hash id "soft synchronization" errors, then set this to false and run your test
again. This is a work-around until we can resolve some issues with NetworkManagerOwner and
NetworkManager.Singleton.
Declaration
protected bool m_CreateServerFirst
Field Value
Type | Description |
---|---|
bool |
m_NetworkManagers
All the NetworkManager instances instantiated and tracked within the current test
Declaration
protected NetworkManager[] m_NetworkManagers
Field Value
Type | Description |
---|---|
NetworkManager[] |
m_NetworkTopologyType
The network topology type being used by the test.
Declaration
protected NetworkTopologyTypes m_NetworkTopologyType
Field Value
Type | Description |
---|---|
NetworkTopologyTypes |
m_PlayerNetworkObjects
Contains each client relative set of player NetworkObject instances [Client Relative set of player instances][The player instance ClientId][The player instance's NetworkObject] Example: To get the player instance with a ClientId of 3 that was instantiated (relative) on the player instance with a ClientId of 2 m_PlayerNetworkObjects[2][3]
Declaration
protected Dictionary<ulong, Dictionary<ulong, NetworkObject>> m_PlayerNetworkObjects
Field Value
Type | Description |
---|---|
Dictionary<ulong, Dictionary<ulong, NetworkObject>> |
m_PlayerPrefab
The default player prefab that is automatically generated and assigned to NetworkManager instances.
See also: The virtual method OnCreatePlayerPrefab() that is invoked after the player prefab has been created.
Declaration
protected GameObject m_PlayerPrefab
Field Value
Type | Description |
---|---|
GameObject |
m_ServerNetworkManager
The Server NetworkManager instance instantiated and tracked within the current test
Declaration
protected NetworkManager m_ServerNetworkManager
Field Value
Type | Description |
---|---|
NetworkManager |
m_TargetFrameRate
Defines the target frame rate to use during a test.
Declaration
protected int m_TargetFrameRate
Field Value
Type | Description |
---|---|
int |
m_UseHost
Determines if a host will be used (default is true).
Declaration
protected bool m_UseHost
Field Value
Type | Description |
---|---|
bool |
s_DefaultWaitForTick
A generic default WaitForSecondsRealtime calculated from the k_TickFrequency.
Declaration
protected static WaitForSecondsRealtime s_DefaultWaitForTick
Field Value
Type | Description |
---|---|
WaitForSecondsRealtime |
s_GlobalNetworkObjects
Registered list of all NetworkObjects spawned. Format is as follows: [ClientId-side where this NetworkObject instance resides][NetworkObjectId][NetworkObject] Where finding the NetworkObject with a NetworkObjectId of 10 on ClientId of 2 would be: s_GlobalNetworkObjects[2][10] To find the client or server player objects please see: m_PlayerNetworkObjects
Declaration
protected static Dictionary<ulong, Dictionary<ulong, NetworkObject>> s_GlobalNetworkObjects
Field Value
Type | Description |
---|---|
Dictionary<ulong, Dictionary<ulong, NetworkObject>> |
s_GlobalTimeoutHelper
A generic time out helper used with wait conditions.
Declaration
protected static TimeoutHelper s_GlobalTimeoutHelper
Field Value
Type | Description |
---|---|
TimeoutHelper |
Properties
LogAllMessages
Determines if all NetcodeIntegrationTest related messages should be logged or not.
Declaration
protected virtual bool LogAllMessages { get; }
Property Value
Type | Description |
---|---|
bool |
NumberOfClients
Specifies the number of client instances to be created for the integration test.
Declaration
protected abstract int NumberOfClients { get; }
Property Value
Type | Description |
---|---|
int |
Remarks
Client-Server network topology:
When running as a host the total number of clients will be NumberOfClients + 1.
See the calculation for TotalClients.
Distributed Authority network topology:
When connecting to a CMB server, if the NumberOfClients == 0 then a session owner client will
be automatically added in order to start the session and the private internal m_NumberOfClients value, which
is initialized as NumberOfClients, will be incremented by 1 making TotalClients yield the
same results as if we were running a Host where it will effectively be NumberOfClients
TotalClients
Total number of clients that should be connected at any point during a test.
Declaration
protected int TotalClients { get; }
Property Value
Type | Description |
---|---|
int |
Remarks
When using the CMB Service, we ignore if m_UseHost is true.
m_BypassConnectionTimeout
When set to true, this will bypass the entire wait for clients to connect process.
Declaration
protected bool m_BypassConnectionTimeout { get; set; }
Property Value
Type | Description |
---|---|
bool |
Remarks
CAUTION: Setting this to true will bypass other helper identification related code, so this should only be used for connection failure oriented testing
m_DistributedAuthority
Returns true if using a distributed authority network topology for the test.
Declaration
protected bool m_DistributedAuthority { get; }
Property Value
Type | Description |
---|---|
bool |
m_EnableTimeTravel
Enables "Time Travel" within the test, which swaps the time provider for the SDK from Unity's Time class to MockTimeProvider, and also swaps the transport implementation from UnityTransport to MockTransport.
This enables five important things that help with both performance and determinism of tests that involve a lot of time and waiting:
- It allows time to move in a completely deterministic way (testing that something happens after n seconds, the test will always move exactly n seconds with no chance of any variability in the timing),
- It allows skipping periods of time without actually waiting that amount of time, while still simulating SDK frames as if that time were passing,
- It dissociates the SDK's update loop from Unity's update loop, allowing us to simulate SDK frame updates without waiting for Unity to process things like physics, animation, and rendering that aren't relevant to the test,
- It dissociates the SDK's messaging system from the networking hardware, meaning there's no delay between a message being sent and it being received, allowing us to deterministically rely on the message being received within specific time frames for the test, and
- It allows tests to be written without the use of coroutines, which not only improves the test's runtime, but also results in easier-to-read callstacks and removes the possibility for an assertion to result in the test hanging.
When time travel is enabled, the following methods become available:
TimeTravel(double, int): Simulates a specific number of frames passing over a specific time period TimeTravelToNextTick(): Skips forward to the next tick, siumlating at the current application frame rate WaitForConditionOrTimeOutWithTimeTravel(Func<bool>, int): Simulates frames at the application frame rate until the given condition is true WaitForMessageReceivedWithTimeTravel<T>(List<NetworkManager>, ReceiptType): Simulates frames at the application frame rate until the required message is received WaitForMessagesReceivedWithTimeTravel(List<Type>, List<NetworkManager>, ReceiptType): Simulates frames at the application frame rate until the required messages are received StartServerAndClientsWithTimeTravel(): Starts a server and client and allows them to connect via simulated frames CreateAndStartNewClientWithTimeTravel(): Creates a client and waits for it to connect via simulated frames WaitForClientsConnectedOrTimeOutWithTimeTravel(NetworkManager[]) Simulates frames at the application frame rate until the given clients are connected StopOneClientWithTimeTravel(NetworkManager, bool): Stops a client and simulates frames until it's fully disconnected.
When time travel is enabled, NetcodeIntegrationTest will automatically use these in its methods when doing things like automatically connecting clients during SetUp.
Additionally, the following methods replace their non-time-travel equivalents with variants that are not coroutines: OnTimeTravelStartedServerAndClients() - called when server and clients are started OnTimeTravelServerAndClientsConnected() - called when server and clients are connected
Note that all of the non-time travel functions can still be used even when time travel is enabled - this is sometimes needed for, e.g., testing NetworkAnimator, where the unity update loop needs to run to process animations. However, it's VERY important to note here that, because the SDK will not be operating based on real-world time but based on the frozen time that's locked in from MockTimeProvider, actions that pass 10 seconds apart by real-world clock time will be perceived by the SDK as having happened simultaneously if you don't call TimeTravel(double) to cover the equivalent time span in the mock time provider. (Calling TimeTravel(double) instead of TimeTravel(double, int) will move time forward without simulating any frames, which, in the case where real-world time has passed, is likely more desirable). In most cases, this desynch won't affect anything, but it is worth noting that it happens just in case a tested system depends on both the unity update loop happening and time moving forward.
Declaration
protected virtual bool m_EnableTimeTravel { get; }
Property Value
Type | Description |
---|---|
bool |
m_EnableVerboseDebug
Determines if VerboseDebug(string) will generate a console log message.
Declaration
protected bool m_EnableVerboseDebug { get; set; }
Property Value
Type | Description |
---|---|
bool |
m_SetupIsACoroutine
If this is false, SetUp will call OnInlineSetUp instead of OnSetUp. This is a performance advantage when not using the coroutine functionality, as a coroutine that has no yield instructions in it will nonetheless still result in delaying the continuation of the method that called it for a full frame after it returns.
Declaration
protected virtual bool m_SetupIsACoroutine { get; }
Property Value
Type | Description |
---|---|
bool |
m_TearDownIsACoroutine
If this is false, TearDown will call OnInlineTearDown instead of OnTearDown. This is a performance advantage when not using the coroutine functionality, as a coroutine that has no yield instructions in it will nonetheless still result in delaying the continuation of the method that called it for a full frame after it returns.
Declaration
protected virtual bool m_TearDownIsACoroutine { get; }
Property Value
Type | Description |
---|---|
bool |
m_UseCmbService
Indicates whether the currently running tests are targeting the hosted CMB Service
Declaration
protected bool m_UseCmbService { get; }
Property Value
Type | Description |
---|---|
bool |
Remarks
Can only be true if UseCMBService() returns true.
Methods
AssertOnTimeout(string, TimeoutHelper)
Just a helper function to avoid having to write the entire assert just to check if you timed out.
Declaration
protected void AssertOnTimeout(string timeOutErrorMessage, TimeoutHelper assignedTimeoutHelper = null)
Parameters
Type | Name | Description |
---|---|---|
string | timeOutErrorMessage | The error message to log if a time out has occurred. |
TimeoutHelper | assignedTimeoutHelper | Optional TimeoutHelper instance used during a conditional wait. |
Remarks
If no TimeoutHelper is provided, then the s_GlobalTimeoutHelper will be used.
CanClientsLoad()
Override this method to control when clients can fake-load a scene.
Declaration
protected virtual bool CanClientsLoad()
Returns
Type | Description |
---|---|
bool | true or false |
CanClientsUnload()
Override this method to control when clients can fake-unload a scene.
Declaration
protected virtual bool CanClientsUnload()
Returns
Type | Description |
---|---|
bool | true or false |
CanDestroyNetworkObject(NetworkObject)
Override this to filter out the NetworkObjects that you want to allow to persist between integration tests. DestroySceneNetworkObjects() ShutdownAndCleanUp()
Declaration
protected virtual bool CanDestroyNetworkObject(NetworkObject networkObject)
Parameters
Type | Name | Description |
---|---|---|
NetworkObject | networkObject | the network object in question to be destroyed |
Returns
Type | Description |
---|---|
bool | true or false |
CanStartServerAndClients()
Override this method and return false in order to be able to manually control when the server and clients are started.
Declaration
protected virtual bool CanStartServerAndClients()
Returns
Type | Description |
---|---|
bool | true or false |
ClientNetworkManagerPostStartInit()
Invoked after the initial start sequence.
Declaration
protected void ClientNetworkManagerPostStartInit()
ConfigureFramesPerTick()
Recalculates the m_TickFrequency and m_FramesPerTick that is used in TimeTravelAdvanceTick().
Declaration
protected void ConfigureFramesPerTick()
CoroutineShutdownAndCleanUp()
Internally used Coroutine that handles cleaning up during tear down.
Declaration
protected IEnumerator CoroutineShutdownAndCleanUp()
Returns
Type | Description |
---|---|
IEnumerator |
CreateAndStartNewClient()
This will create, start, and connect a new client while in the middle of an integration test.
Declaration
protected IEnumerator CreateAndStartNewClient()
Returns
Type | Description |
---|---|
IEnumerator | An IEnumerator to be used in a coroutine for asynchronous execution. |
CreateAndStartNewClientWithTimeTravel()
This will create, start, and connect a new client while in the middle of an integration test.
Declaration
protected void CreateAndStartNewClientWithTimeTravel()
CreateNetworkObjectPrefab(string)
Creates a basic NetworkObject test prefab, assigns it to a new NetworkPrefab entry, and then adds it to the server and client(s) NetworkManagers' NetworkConfig.NetworkPrefab lists.
Declaration
protected GameObject CreateNetworkObjectPrefab(string baseName)
Parameters
Type | Name | Description |
---|---|---|
string | baseName | the basic name to be used for each instance |
Returns
Type | Description |
---|---|
GameObject | The GameObject assigned to the new NetworkPrefab entry |
CreateNewClient()
This will create a new client while in the middle of an integration test. Use StartClient(NetworkManager) to start the created client.
Declaration
protected NetworkManager CreateNewClient()
Returns
Type | Description |
---|---|
NetworkManager | The newly created NetworkManager. |
CreateServerAndClients()
Will create NumberOfClients number of clients. To create a specific number of clients CreateServerAndClients(int)
Declaration
protected void CreateServerAndClients()
CreateServerAndClients(int)
Creates the server and clients
Declaration
protected void CreateServerAndClients(int numberOfClients)
Parameters
Type | Name | Description |
---|---|---|
int | numberOfClients | The number of client instances to create |
DeRegisterSceneManagerHandler()
De-Registers from the CanClientsLoad and CanClientsUnload events of the ClientSceneHandler (default is IntegrationTestSceneHandler).
Declaration
protected void DeRegisterSceneManagerHandler()
DeregisterNetworkObject(ulong, ulong)
Overloaded version of DeregisterNetworkObject(NetworkObject).
Used by ObjectNameIdentifier to de-register a spawned NetworkObject instance.
Declaration
public static void DeregisterNetworkObject(ulong localClientId, ulong networkObjectId)
Parameters
Type | Name | Description |
---|---|---|
ulong | localClientId | The client instance identifier of the spawned NetworkObject instance. |
ulong | networkObjectId | The NetworkObjectId of the spawned instance. |
DeregisterNetworkObject(NetworkObject)
Used by ObjectNameIdentifier to de-register a spawned NetworkObject instance.
Declaration
public static void DeregisterNetworkObject(NetworkObject networkObject)
Parameters
Type | Name | Description |
---|---|---|
NetworkObject | networkObject | The NetworkObject being de-registered for a test in progress. |
DestroySceneNetworkObjects()
Destroys all NetworkObjects at the end of a test cycle.
Declaration
protected void DestroySceneNetworkObjects()
EnableMessageLogging()
For debugging purposes, this will turn on verbose logging of all messages and batches sent and received
Declaration
protected void EnableMessageLogging()
GetAuthorityNetworkManager()
Gets the current authority of the network session. When using the hosted CMB service this will be the client who is the session owner. Otherwise, returns the server NetworkManager
Declaration
protected NetworkManager GetAuthorityNetworkManager()
Returns
Type | Description |
---|---|
NetworkManager | The NetworkManager instance that is the current authority |
GetFrameRate()
A virtual method that can be overriden to adjust the frame rate used when starting NetworkManager instances.
Declaration
protected virtual int GetFrameRate()
Returns
Type | Description |
---|---|
int | The frame rate to use. |
GetNonAuthorityNetworkManager()
Gets a non-session owner NetworkManager.
Declaration
protected NetworkManager GetNonAuthorityNetworkManager()
Returns
Type | Description |
---|---|
NetworkManager | A NetworkManager instance that will not be the session owner |
GetNonAuthorityNetworkManager(int)
Gets the non-session owner NetworkManager indicated by the passed in index.
Declaration
protected NetworkManager GetNonAuthorityNetworkManager(int nonAuthorityIndex)
Parameters
Type | Name | Description |
---|---|---|
int | nonAuthorityIndex | Index of the number of the non-authority client wanted |
Returns
Type | Description |
---|---|
NetworkManager | The NetworkManager instance that is not the session owner at the given index |
GetTickRate()
A virtual method that can be overriden to adjust the tick rate used when starting NetworkManager instances.
Declaration
protected virtual uint GetTickRate()
Returns
Type | Description |
---|---|
uint | The tick rate to use. |
OnCanSceneCleanUpUnload(Scene)
Detemines if a scene can be cleaned and unloaded during the tear down phase (UnloadRemainingScenes()).
Declaration
protected bool OnCanSceneCleanUpUnload(Scene scene)
Parameters
Type | Name | Description |
---|---|---|
Scene | scene | The Scene. |
Returns
Type | Description |
---|---|
bool | true or false |
OnCreatePlayerPrefab()
Override this to add components or adjustments to the default player prefab m_PlayerPrefab
Declaration
protected virtual void OnCreatePlayerPrefab()
OnGetNetworkTopologyType()
Override this virtual method to control what kind of NetworkTopologyTypes to use.
Declaration
protected virtual NetworkTopologyTypes OnGetNetworkTopologyType()
Returns
Type | Description |
---|---|
NetworkTopologyTypes |
OnInlineSetup()
Called before creating and starting the server and clients Note: For AllTests and PerTest mode integration tests. For those two modes, if you want to have access to the server or client NetworkManagers then override OnServerAndClientsCreated(). m_ServerNetworkManager and m_ClientNetworkManagers
Declaration
protected virtual void OnInlineSetup()
OnInlineTearDown()
The inline version of tear down that is used if m_TearDownIsACoroutine is false.
Declaration
protected virtual void OnInlineTearDown()
OnNewClientCreated(NetworkManager)
CreateAndStartNewClient Only Invoked when the newly created client has been created
Declaration
protected virtual void OnNewClientCreated(NetworkManager networkManager)
Parameters
Type | Name | Description |
---|---|---|
NetworkManager | networkManager | The NetworkManager instance of the client. |
OnNewClientStarted(NetworkManager)
CreateAndStartNewClient Only Invoked when the newly created client has been created and started
Declaration
protected virtual void OnNewClientStarted(NetworkManager networkManager)
Parameters
Type | Name | Description |
---|---|---|
NetworkManager | networkManager | The NetworkManager instance of the client. |
OnNewClientStartedAndConnected(NetworkManager)
CreateAndStartNewClient Only Invoked when the newly created client has been created, started, and connected to the server-host.
Declaration
protected virtual void OnNewClientStartedAndConnected(NetworkManager networkManager)
Parameters
Type | Name | Description |
---|---|---|
NetworkManager | networkManager | The NetworkManager instance of the client. |
OnOneTimeSetup()
Override this method to do any one time setup configurations.
Declaration
protected virtual void OnOneTimeSetup()
OnOneTimeTearDown()
Override this method to do handle cleaning up once the test(s) within the child derived class have completed Note: For AllTests mode this is called before ShutdownAndCleanUp.
Declaration
protected virtual void OnOneTimeTearDown()
OnPlayerPrefabGameObjectCreated()
Invoked immediately after the player prefab GameObject is created prior to adding a NetworkObject component
Declaration
protected virtual void OnPlayerPrefabGameObjectCreated()
OnServerAndClientsConnected()
Invoked after the server and clients have started and verified their connections with each other.
Declaration
protected virtual IEnumerator OnServerAndClientsConnected()
Returns
Type | Description |
---|---|
IEnumerator |
OnServerAndClientsCreated()
This is invoked before the server and client(s) are started. Override this method if you want to make any adjustments to their NetworkManager instances.
Declaration
protected virtual void OnServerAndClientsCreated()
OnSetIntegrationTestMode()
The very first thing invoked during the OneTimeSetup() that determines how this integration test handles NetworkManager instantiation and destruction. NetcodeIntegrationTest.NetworkManagerInstatiationMode Override this method to change the default mode: AllTests
Declaration
protected virtual NetcodeIntegrationTest.NetworkManagerInstatiationMode OnSetIntegrationTestMode()
Returns
Type | Description |
---|---|
NetcodeIntegrationTest.NetworkManagerInstatiationMode |
OnSetVerboseDebug()
Override this and return true if you need to troubleshoot a hard to track bug within an integration test.
Declaration
protected virtual bool OnSetVerboseDebug()
Returns
Type | Description |
---|---|
bool | true or false |
OnSetup()
Called before creating and starting the server and clients Note: For AllTests and PerTest mode integration tests. For those two modes, if you want to have access to the server or client NetworkManagers then override OnServerAndClientsCreated(). m_ServerNetworkManager and m_ClientNetworkManagers
Declaration
protected virtual IEnumerator OnSetup()
Returns
Type | Description |
---|---|
IEnumerator |
OnStartedServerAndClients()
Invoked after the server and clients have started. Note: No connection verification has been done at this point
Declaration
protected virtual IEnumerator OnStartedServerAndClients()
Returns
Type | Description |
---|---|
IEnumerator |
OnTearDown()
Note: For PerTest mode this is called before ShutdownAndCleanUp.
Declaration
protected virtual IEnumerator OnTearDown()
Returns
Type | Description |
---|---|
IEnumerator |
OnTimeTravelServerAndClientsConnected()
Invoked after the server and clients have started and verified their connections with each other.
Declaration
protected virtual void OnTimeTravelServerAndClientsConnected()
OnTimeTravelStartedServerAndClients()
Invoked after the server and clients have started. Note: No connection verification has been done at this point
Declaration
protected virtual void OnTimeTravelStartedServerAndClients()
OneTimeSetup()
The NUnit.Framework.OneTimeSetUpAttribute decorated method that is invoked once per derived NetcodeIntegrationTest instance.
Declaration
[OneTimeSetUp]
public void OneTimeSetup()
OneTimeTearDown()
The NUnit.Framework.OneTimeTearDownAttribute decorated method that is invoked once upon all tests finishing.
Declaration
[OneTimeTearDown]
public void OneTimeTearDown()
RegisterNetworkObject(NetworkObject)
Used by ObjectNameIdentifier to register spawned NetworkObject instances.
Declaration
public static void RegisterNetworkObject(NetworkObject networkObject)
Parameters
Type | Name | Description |
---|---|---|
NetworkObject | networkObject | The NetworkObject being registered for a test in progress. |
RegisterSceneManagerHandler()
Registers the CanClientsLoad and CanClientsUnload events of the ClientSceneHandler. The default is: IntegrationTestSceneHandler.
Declaration
protected void RegisterSceneManagerHandler()
SetDistributedAuthorityProperties(NetworkManager)
Can be used to set the distributed authority properties for a test.
Declaration
protected void SetDistributedAuthorityProperties(NetworkManager networkManager)
Parameters
Type | Name | Description |
---|---|---|
NetworkManager | networkManager | The NetworkManager to configure. |
SetTimeTravelSimulatedDropRate(float)
When using time travel, you can use this method to simulate packet loss conditions.
Declaration
protected void SetTimeTravelSimulatedDropRate(float dropRatePercent)
Parameters
Type | Name | Description |
---|---|---|
float | dropRatePercent | The percentage of packets to be dropped while time traveling. |
SetTimeTravelSimulatedLatency(float)
When using time travel, you can use this method to simulate latency conditions.
Declaration
protected void SetTimeTravelSimulatedLatency(float latencySeconds)
Parameters
Type | Name | Description |
---|---|---|
float | latencySeconds | The amount of latency to be applied prior to invoking TimeTravel(double, int) |
SetTimeTravelSimulatedLatencyJitter(float)
When using time travel, you can use this method to simulate packet jitter conditions.
Declaration
protected void SetTimeTravelSimulatedLatencyJitter(float jitterSeconds)
Parameters
Type | Name | Description |
---|---|---|
float | jitterSeconds | The amount of packet jitter to be applied while time traveling. |
SetUp()
The UnityEngine.TestTools.UnitySetUpAttribute decorated method that is invoked once per NUnit.Framework.TestFixtureAttribute instance or just once if none.
Declaration
public IEnumerator SetUp()
Returns
Type | Description |
---|---|
IEnumerator |
ShouldCheckForSpawnedPlayers()
A virtal method that, when overriden, provides control over whether to spawn a player or not.
Declaration
protected virtual bool ShouldCheckForSpawnedPlayers()
Returns
Type | Description |
---|---|
bool | true if players should be spawned and false if they should not. |
ShouldWaitForNewClientToConnect(NetworkManager)
CreateAndStartNewClient Only Override this method to bypass the waiting for a client to connect.
Declaration
protected virtual bool ShouldWaitForNewClientToConnect(NetworkManager networkManager)
Parameters
Type | Name | Description |
---|---|---|
NetworkManager | networkManager | The NetworkManager instance of the client. |
Returns
Type | Description |
---|---|
bool | true if the test should wait for the client to connect; otherwise, it returns false. |
Remarks
Use this for testing connection and disconnection scenarios
ShutdownAndCleanUp()
This shuts down all NetworkManager instances registered via the NetcodeIntegrationTestHelpers class and cleans up the test runner scene of any left over NetworkObjects. DestroySceneNetworkObjects()
Declaration
protected void ShutdownAndCleanUp()
SimulateOneFrame()
Simulates one SDK frame. This can be used even without TimeTravel, though it's of somewhat less use without TimeTravel, as, without the mock transport, it will likely not provide enough time for any sent messages to be received even if called dozens of times.
Declaration
public static void SimulateOneFrame()
SpawnObject(GameObject, NetworkManager, bool)
Overloaded method SpawnObject(NetworkObject, NetworkManager, bool)
Declaration
protected GameObject SpawnObject(GameObject prefabGameObject, NetworkManager owner, bool destroyWithScene = false)
Parameters
Type | Name | Description |
---|---|---|
GameObject | prefabGameObject | the prefab GameObject to spawn |
NetworkManager | owner | the owner of the instance |
bool | destroyWithScene | default is false |
Returns
Type | Description |
---|---|
GameObject | The GameObject of the newly spawned NetworkObject. |
SpawnObjects(GameObject, NetworkManager, int, bool)
Overloaded method SpawnObjects(NetworkObject, NetworkManager, int, bool).
Declaration
protected List<GameObject> SpawnObjects(GameObject prefabGameObject, NetworkManager owner, int count, bool destroyWithScene = false)
Parameters
Type | Name | Description |
---|---|---|
GameObject | prefabGameObject | the prefab GameObject to spawn |
NetworkManager | owner | the owner of the instance |
int | count | number of instances to create and spawn |
bool | destroyWithScene | default is false |
Returns
Type | Description |
---|---|
List<GameObject> | A List<T> of GameObjects spawned. |
SpawnPlayerObject(GameObject, NetworkManager, bool)
Overloaded method SpawnObject(NetworkObject, NetworkManager, bool)
Declaration
protected GameObject SpawnPlayerObject(GameObject prefabGameObject, NetworkManager owner, bool destroyWithScene = false)
Parameters
Type | Name | Description |
---|---|---|
GameObject | prefabGameObject | the prefab GameObject to spawn |
NetworkManager | owner | the owner of the instance |
bool | destroyWithScene | default is false |
Returns
Type | Description |
---|---|
GameObject | The GameObject of the newly spawned player's NetworkObject. |
StartClient(NetworkManager)
Starts and connects the given networkManager as a client while in the middle of an integration test.
Declaration
protected IEnumerator StartClient(NetworkManager networkManager)
Parameters
Type | Name | Description |
---|---|---|
NetworkManager | networkManager | The network manager to start and connect |
Returns
Type | Description |
---|---|
IEnumerator | An IEnumerator to be used in a coroutine for asynchronous execution. |
StartServerAndClients()
This starts the server and clients as long as CanStartServerAndClients() returns true.
Declaration
protected IEnumerator StartServerAndClients()
Returns
Type | Description |
---|---|
IEnumerator |
StartServerAndClientsWithTimeTravel()
This starts the server and clients as long as CanStartServerAndClients() returns true.
Declaration
protected void StartServerAndClientsWithTimeTravel()
StopOneClient(NetworkManager, bool)
This will stop the given NetworkManager instance while in the middle of an integration test. The instance is then removed from the lists of managed instances (m_NetworkManagers, m_ClientNetworkManagers).
Declaration
protected IEnumerator StopOneClient(NetworkManager networkManager, bool destroy = false)
Parameters
Type | Name | Description |
---|---|---|
NetworkManager | networkManager | The NetworkManager instance of the client to stop. |
bool | destroy | Whether the NetworkManager instance should be destroyed after stopping. Defaults to false. |
Returns
Type | Description |
---|---|
IEnumerator | An IEnumerator to be used in a coroutine for asynchronous execution. |
Remarks
If there are no other references to the managed instance, it will be destroyed regardless of the destroy parameter. To avoid this, save a reference to the NetworkManager instance before calling this method.
StopOneClientWithTimeTravel(NetworkManager, bool)
This will stop the given NetworkManager instance while in the middle of a time travel integration test. The instance is then removed from the lists of managed instances (m_NetworkManagers, m_ClientNetworkManagers).
Declaration
protected void StopOneClientWithTimeTravel(NetworkManager networkManager, bool destroy = false)
Parameters
Type | Name | Description |
---|---|---|
NetworkManager | networkManager | The NetworkManager instance of the client to stop. |
bool | destroy | Whether the NetworkManager instance should be destroyed after stopping. Defaults to false. |
Remarks
If there are no other references to the managed instance, it will be destroyed regardless of the destroy parameter. To avoid this, save a reference to the NetworkManager instance before calling this method.
TearDown()
The UnityEngine.TestTools.UnityTearDownAttribute decorated method that is invoked during an integration test's tear down.
Declaration
public IEnumerator TearDown()
Returns
Type | Description |
---|---|
IEnumerator |
TimeTravel(double, int)
Simulate a number of frames passing over a specific amount of time. The delta time simulated for each frame will be evenly divided as time/numFrames This will only simulate the netcode update loop, as well as update events on NetworkBehaviour instances, and will not simulate any Unity update processes (physics, etc)
Declaration
protected static void TimeTravel(double amountOfTimeInSeconds, int numFramesToSimulate)
Parameters
Type | Name | Description |
---|---|---|
double | amountOfTimeInSeconds | The total amount of time to simulate, in seconds |
int | numFramesToSimulate | The number of frames to distribute the time across |
TimeTravelAdvanceTick()
Helper function to time travel exactly one tick's worth of time at the current frame and tick rates. This is NetcodeIntegrationTest instance relative and will automatically adjust based on GetFrameRate() and GetTickRate().
Declaration
protected void TimeTravelAdvanceTick()
TimeTravelToNextTick()
Helper function to time travel exactly one tick's worth of time at the current frame and tick rates. ** Is based on the global k_DefaultTickRate and is not local to each NetcodeIntegrationTest instance **
Declaration
public static void TimeTravelToNextTick()
UseCMBService()
Indicates whether a hosted CMB service is available.
Declaration
protected virtual bool UseCMBService()
Returns
Type | Description |
---|---|
bool | true if a DAHost test should run against a hosted CMB service instance; otherwise it returns false. |
Remarks
Override to return false to ensure a set of tests never runs against the hosted service
VerboseDebug(string)
Used to display the various integration test stages and can be used to log verbose information for troubleshooting an integration test.
Declaration
protected void VerboseDebug(string msg)
Parameters
Type | Name | Description |
---|---|---|
string | msg | The debug message to be logged when verbose debugging is enabled |
WaitForClientsConnectedOrTimeOut()
Overloaded method that just passes in all clients to WaitForClientsConnectedOrTimeOut(NetworkManager[])
Declaration
protected IEnumerator WaitForClientsConnectedOrTimeOut()
Returns
Type | Description |
---|---|
IEnumerator |
WaitForClientsConnectedOrTimeOut(NetworkManager[])
Validates that all remote clients (i.e. non-server) detect they are connected to the server and that the server reflects the appropriate number of clients have connected or it will time out.
Declaration
protected IEnumerator WaitForClientsConnectedOrTimeOut(NetworkManager[] clientsToCheck)
Parameters
Type | Name | Description |
---|---|---|
NetworkManager[] | clientsToCheck | An array of clients to be checked |
Returns
Type | Description |
---|---|
IEnumerator |
WaitForClientsConnectedOrTimeOutWithTimeTravel()
Overloaded method that just passes in all clients to WaitForClientsConnectedOrTimeOut(NetworkManager[]) Uses time travel to simulate this for the given number of frames, simulating delta times at the application frame rate.
Declaration
protected bool WaitForClientsConnectedOrTimeOutWithTimeTravel()
Returns
Type | Description |
---|---|
bool | true or false |
WaitForClientsConnectedOrTimeOutWithTimeTravel(NetworkManager[])
Validates that all remote clients (i.e. non-server) detect they are connected to the server and that the server reflects the appropriate number of clients have connected or it will time out. Uses time travel to simulate this for the given number of frames, simulating delta times at the application frame rate.
Declaration
protected bool WaitForClientsConnectedOrTimeOutWithTimeTravel(NetworkManager[] clientsToCheck)
Parameters
Type | Name | Description |
---|---|---|
NetworkManager[] | clientsToCheck | An array of clients to be checked |
Returns
Type | Description |
---|---|
bool | true or false |
WaitForConditionOrTimeOut(Func<bool>, TimeoutHelper)
Waits for the function condition to return true or it will time out. This will operate at the current m_ServerNetworkManager.NetworkConfig.TickRate and allow for a unique TimeoutHelper handler (if none then it uses the default) Notes: This provides more stability when running integration tests that could be impacted by: -how the integration test is being executed (i.e. in editor or in a stand alone build) -potential platform performance issues (i.e. VM is throttled or maxed) Note: For more complex tests, ConditionalPredicateBase and the overloaded version of this method
Declaration
public static IEnumerator WaitForConditionOrTimeOut(Func<bool> checkForCondition, TimeoutHelper timeOutHelper = null)
Parameters
Type | Name | Description |
---|---|---|
Func<bool> | checkForCondition | the conditional function to determine if the condition has been reached. |
TimeoutHelper | timeOutHelper | the TimeoutHelper used to handle timing out the wait condition. |
Returns
Type | Description |
---|---|
IEnumerator |
WaitForConditionOrTimeOut(Func<StringBuilder, bool>, TimeoutHelper)
Waits until the specified condition returns true or a timeout occurs, then asserts if the timeout was reached. This overload allows the condition to provide additional error details via a StringBuilder.
Declaration
protected IEnumerator WaitForConditionOrTimeOut(Func<StringBuilder, bool> checkForCondition, TimeoutHelper timeOutHelper = null)
Parameters
Type | Name | Description |
---|---|---|
Func<StringBuilder, bool> | checkForCondition | A delegate that takes a StringBuilder for error details and returns true when the desired condition is met. |
TimeoutHelper | timeOutHelper | An optional TimeoutHelper to control the timeout period. If null, the default timeout is used. |
Returns
Type | Description |
---|---|
IEnumerator | An IEnumerator for use in Unity coroutines. |
WaitForConditionOrTimeOut(IConditionalPredicate, TimeoutHelper)
This version accepts an IConditionalPredicate implementation to provide more flexibility for checking complex conditional cases.
Declaration
public static IEnumerator WaitForConditionOrTimeOut(IConditionalPredicate conditionalPredicate, TimeoutHelper timeOutHelper = null)
Parameters
Type | Name | Description |
---|---|---|
IConditionalPredicate | conditionalPredicate | An IConditionalPredicate implementation used to determine if the condition(s) has/have been met. |
TimeoutHelper | timeOutHelper | the TimeoutHelper used to handle timing out the wait condition. |
Returns
Type | Description |
---|---|
IEnumerator |
WaitForConditionOrTimeOutWithTimeTravel(Func<bool>, int)
Waits for the function condition to return true or it will time out. Uses time travel to simulate this for the given number of frames, simulating delta times at the application frame rate.
Declaration
public bool WaitForConditionOrTimeOutWithTimeTravel(Func<bool> checkForCondition, int maxTries = 60)
Parameters
Type | Name | Description |
---|---|---|
Func<bool> | checkForCondition | the conditional function to determine if the condition has been reached. |
int | maxTries | the maximum times to check for the condition (default is 60). |
Returns
Type | Description |
---|---|
bool | true or false |
WaitForConditionOrTimeOutWithTimeTravel(IConditionalPredicate, int)
This version accepts an IConditionalPredicate implementation to provide more flexibility for checking complex conditional cases. Uses time travel to simulate this for the given number of frames, simulating delta times at the application frame rate.
Declaration
public bool WaitForConditionOrTimeOutWithTimeTravel(IConditionalPredicate conditionalPredicate, int maxTries = 60)
Parameters
Type | Name | Description |
---|---|---|
IConditionalPredicate | conditionalPredicate | An IConditionalPredicate implementation used to determine if the condition(s) has/have been met. |
int | maxTries | the maximum times to check for the condition (default is 60). |
Returns
Type | Description |
---|---|
bool | true or false |
WaitForTicks(NetworkManager, int)
Yields until specified amount of network ticks and the expected number of frames has been passed.
Declaration
protected IEnumerator WaitForTicks(NetworkManager networkManager, int count)
Parameters
Type | Name | Description |
---|---|---|
NetworkManager | networkManager | The relative NetworkManager waiting for a specific tick. |
int | count | How many ticks to wait for. |
Returns
Type | Description |
---|---|
IEnumerator |