Class DeferredMessagingTest
Inherited Members
Namespace: Unity.Netcode.RuntimeTests
Assembly: Unity.Netcode.RuntimeTests.dll
Syntax
public class DeferredMessagingTest : NetcodeIntegrationTest
Properties
NumberOfClients
Declaration
protected override int NumberOfClients { get; }
Property Value
Type | Description |
---|---|
int |
Overrides
m_EnableTimeTravel
Enables "Time Travel" within the test, which swaps the time provider for the SDK from Unity's
Time class to Mock
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:
Time
When time travel is enabled, Netcode
Additionally, the following methods replace their non-time-travel equivalents with variants that are not coroutines:
On
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
Time
Declaration
protected override bool m_EnableTimeTravel { get; }
Property Value
Type | Description |
---|---|
bool |
Overrides
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 override bool m_SetupIsACoroutine { get; }
Property Value
Type | Description |
---|---|
bool |
Overrides
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 override bool m_TearDownIsACoroutine { get; }
Property Value
Type | Description |
---|---|
bool |
Overrides
Methods
OnInlineSetup()
Called before creating and starting the server and clients
Note: For All
Declaration
protected override void OnInlineSetup()
Overrides
OnInlineTearDown()
Declaration
protected override void OnInlineTearDown()
Overrides
OnNewClientCreated(NetworkManager)
CreateAndStartNewClient Only Invoked when the newly created client has been created
Declaration
protected override void OnNewClientCreated(NetworkManager networkManager)
Parameters
Type | Name | Description |
---|---|---|
Network |
networkManager |
Overrides
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 override void OnServerAndClientsCreated()
Overrides
OnTimeTravelServerAndClientsConnected()
Invoked after the server and clients have started and verified their connections with each other.
Declaration
protected override void OnTimeTravelServerAndClientsConnected()
Overrides
WhenAChangeOwnershipMessageArrivesBeforeASpawnArrives_ItIsDeferred()
Declaration
[Test]
public void WhenAChangeOwnershipMessageArrivesBeforeASpawnArrives_ItIsDeferred()
WhenAChangeOwnershipMessageIsDeferred_ItIsProcessedOnSpawn()
Declaration
[Test]
public void WhenAChangeOwnershipMessageIsDeferred_ItIsProcessedOnSpawn()
WhenADeferredMessageIsRemoved_OtherMessagesForDifferentObjectsAreNotRemoved(int)
Declaration
[Test]
public void WhenADeferredMessageIsRemoved_OtherMessagesForDifferentObjectsAreNotRemoved(int timeout)
Parameters
Type | Name | Description |
---|---|---|
int | timeout |
WhenADeferredMessageIsRemoved_OtherMessagesForSameObjectAreRemoved(int)
Declaration
[Test]
public void WhenADeferredMessageIsRemoved_OtherMessagesForSameObjectAreRemoved(int timeout)
Parameters
Type | Name | Description |
---|---|---|
int | timeout |
WhenADespawnArrivesBeforeASpawnArrives_ItIsDeferred()
Declaration
[Test]
public void WhenADespawnArrivesBeforeASpawnArrives_ItIsDeferred()
WhenADespawnIsDeferred_ItIsProcessedOnSpawn()
Declaration
[Test]
public void WhenADespawnIsDeferred_ItIsProcessedOnSpawn()
WhenAMessageIsDeferredForMoreThanTheConfiguredTime_ItIsRemoved(int)
Declaration
[Test]
public void WhenAMessageIsDeferredForMoreThanTheConfiguredTime_ItIsRemoved(int timeout)
Parameters
Type | Name | Description |
---|---|---|
int | timeout |
WhenANetworkVariableDeltaMessageArrivesBeforeASpawnArrives_ItIsDeferred()
Declaration
[Test]
public void WhenANetworkVariableDeltaMessageArrivesBeforeASpawnArrives_ItIsDeferred()
WhenANetworkVariableDeltaMessageIsDeferred_ItIsProcessedOnSpawn()
Declaration
[Test]
public void WhenANetworkVariableDeltaMessageIsDeferred_ItIsProcessedOnSpawn()
WhenASpawnMessageArrivesBeforeThePrefabIsAvailable_ItIsDeferred()
Declaration
[Test]
public void WhenASpawnMessageArrivesBeforeThePrefabIsAvailable_ItIsDeferred()
WhenASpawnMessageIsDeferred_ItIsProcessedOnAddPrefab()
Declaration
[Test]
public void WhenASpawnMessageIsDeferred_ItIsProcessedOnAddPrefab()
WhenAnRpcArrivesBeforeASpawnArrives_ItIsDeferred()
Declaration
[Test]
public void WhenAnRpcArrivesBeforeASpawnArrives_ItIsDeferred()
WhenAnRpcIsDeferred_ItIsProcessedOnSpawn()
Declaration
[Test]
public void WhenAnRpcIsDeferred_ItIsProcessedOnSpawn()
WhenMultipleAddPrefabTriggeredMessagesAreDeferred_TheyAreAllProcessedOnAddNetworkPrefab()
Declaration
[Test]
public void WhenMultipleAddPrefabTriggeredMessagesAreDeferred_TheyAreAllProcessedOnAddNetworkPrefab()
WhenMultipleMessagesForDifferentObjectsAreDeferredForMoreThanTheConfiguredTime_TheyAreAllRemoved(int)
Declaration
[Test]
public void WhenMultipleMessagesForDifferentObjectsAreDeferredForMoreThanTheConfiguredTime_TheyAreAllRemoved(int timeout)
Parameters
Type | Name | Description |
---|---|---|
int | timeout |
WhenMultipleMessagesForTheSameObjectAreDeferredForMoreThanTheConfiguredTime_TheyAreAllRemoved(int)
Declaration
[Test]
public void WhenMultipleMessagesForTheSameObjectAreDeferredForMoreThanTheConfiguredTime_TheyAreAllRemoved(int timeout)
Parameters
Type | Name | Description |
---|---|---|
int | timeout |
WhenMultipleSpawnTriggeredMessagesAreDeferred_TheyAreAllProcessedOnSpawn()
Declaration
[Test]
public void WhenMultipleSpawnTriggeredMessagesAreDeferred_TheyAreAllProcessedOnSpawn()
WhenSpawnTriggeredMessagesAreDeferredBeforeThePrefabIsAdded_AddingThePrefabCausesThemToBeProcessed()
Declaration
[Test]
public void WhenSpawnTriggeredMessagesAreDeferredBeforeThePrefabIsAdded_AddingThePrefabCausesThemToBeProcessed()