Class UniversalRpcTestsBase
Inheritance
UniversalRpcTestsBase
Assembly: solution.dll
Syntax
public class UniversalRpcTestsBase : NetcodeIntegrationTest
Constructors
UniversalRpcTestsBase(HostOrServer)
Declaration
public UniversalRpcTestsBase(NetcodeIntegrationTest.HostOrServer hostOrServer)
Parameters
Fields
m_ServerObject
Declaration
protected GameObject m_ServerObject
Field Value
s_ClientIds
Declaration
protected static ulong[] s_ClientIds
Field Value
Properties
NumberOfClients
Declaration
protected override int NumberOfClients { get; }
Property Value
Overrides
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 override bool m_EnableTimeTravel { get; }
Property Value
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
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
Overrides
Methods
Clear()
Declaration
GetPlayerObject(ulong, ulong)
Declaration
protected UniversalRpcNetworkBehaviour GetPlayerObject(ulong ownerClientId, ulong onClient)
Parameters
Type |
Name |
Description |
ulong |
ownerClientId |
|
ulong |
onClient |
|
Returns
OnCreatePlayerPrefab()
Override this to add components or adjustments to the default player prefab
m_PlayerPrefab
Declaration
protected override void OnCreatePlayerPrefab()
Overrides
OnInlineTearDown()
Declaration
protected override void OnInlineTearDown()
Overrides
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 override void OnOneTimeTearDown()
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
OnSetIntegrationTestMode()
Declaration
protected override NetcodeIntegrationTest.NetworkManagerInstatiationMode OnSetIntegrationTestMode()
Returns
Overrides
OnTimeTravelServerAndClientsConnected()
Invoked after the server and clients have started and verified
their connections with each other.
Declaration
protected override void OnTimeTravelServerAndClientsConnected()
Overrides
RethrowTargetInvocationException(Action)
Declaration
public void RethrowTargetInvocationException(Action action)
Parameters
Type |
Name |
Description |
Action |
action |
|
VerifyLocalReceived(ulong, ulong, string, bool)
Declaration
protected void VerifyLocalReceived(ulong objectOwner, ulong sender, string name, bool verifyReceivedFrom)
Parameters
VerifyLocalReceivedWithParams(ulong, ulong, string, int, bool, float, string)
Declaration
protected void VerifyLocalReceivedWithParams(ulong objectOwner, ulong sender, string name, int i, bool b, float f, string s)
Parameters
VerifyNotReceived(ulong, ulong[])
Declaration
protected void VerifyNotReceived(ulong objectOwner, ulong[] receivedBy)
Parameters
Type |
Name |
Description |
ulong |
objectOwner |
|
ulong[] |
receivedBy |
|
VerifyRemoteReceived(ulong, ulong, string, ulong[], bool, bool)
Declaration
protected void VerifyRemoteReceived(ulong objectOwner, ulong sender, string message, ulong[] receivedBy, bool verifyReceivedFrom, bool waitForMessages = true)
Parameters
VerifyRemoteReceivedWithParams(ulong, ulong, string, ulong[], int, bool, float, string)
Declaration
protected void VerifyRemoteReceivedWithParams(ulong objectOwner, ulong sender, string message, ulong[] receivedBy, int i, bool b, float f, string s)
Parameters
VerifySentToClientsAndHost(ulong, ulong, string)
Declaration
public void VerifySentToClientsAndHost(ulong objectOwner, ulong sender, string methodName)
Parameters
VerifySentToClientsAndHostWithParams(ulong, ulong, string, int, bool, float, string)
Declaration
public void VerifySentToClientsAndHostWithParams(ulong objectOwner, ulong sender, string methodName, int i, bool b, float f, string s)
Parameters
VerifySentToClientsAndHostWithReceivedFrom(ulong, ulong, string)
Declaration
public void VerifySentToClientsAndHostWithReceivedFrom(ulong objectOwner, ulong sender, string methodName)
Parameters
VerifySentToEveryone(ulong, ulong, string)
Declaration
public void VerifySentToEveryone(ulong objectOwner, ulong sender, string methodName)
Parameters
VerifySentToEveryoneWithParams(ulong, ulong, string, int, bool, float, string)
Declaration
public void VerifySentToEveryoneWithParams(ulong objectOwner, ulong sender, string methodName, int i, bool b, float f, string s)
Parameters
VerifySentToEveryoneWithReceivedFrom(ulong, ulong, string)
Declaration
public void VerifySentToEveryoneWithReceivedFrom(ulong objectOwner, ulong sender, string methodName)
Parameters
VerifySentToId(ulong, ulong, ulong, string, bool)
Declaration
public void VerifySentToId(ulong objectOwner, ulong sender, ulong receiver, string methodName, bool verifyReceivedFrom)
Parameters
VerifySentToIdWithParams(ulong, ulong, ulong, string, int, bool, float, string)
Declaration
public void VerifySentToIdWithParams(ulong objectOwner, ulong sender, ulong receiver, string methodName, int i, bool b, float f, string s)
Parameters
VerifySentToMe(ulong, ulong, string)
Declaration
public void VerifySentToMe(ulong objectOwner, ulong sender, string methodName)
Parameters
VerifySentToMeWithParams(ulong, ulong, string, int, bool, float, string)
Declaration
public void VerifySentToMeWithParams(ulong objectOwner, ulong sender, string methodName, int i, bool b, float f, string s)
Parameters
VerifySentToMeWithReceivedFrom(ulong, ulong, string)
Declaration
public void VerifySentToMeWithReceivedFrom(ulong objectOwner, ulong sender, string methodName)
Parameters
VerifySentToNotId(ulong, ulong, ulong, string, bool)
Declaration
public void VerifySentToNotId(ulong objectOwner, ulong sender, ulong notReceiver, string methodName, bool verifyReceivedFrom)
Parameters
VerifySentToNotIdWithParams(ulong, ulong, ulong, string, int, bool, float, string)
Declaration
public void VerifySentToNotIdWithParams(ulong objectOwner, ulong sender, ulong notReceiver, string methodName, int i, bool b, float f, string s)
Parameters
VerifySentToNotMe(ulong, ulong, string)
Declaration
public void VerifySentToNotMe(ulong objectOwner, ulong sender, string methodName)
Parameters
VerifySentToNotMeWithParams(ulong, ulong, string, int, bool, float, string)
Declaration
public void VerifySentToNotMeWithParams(ulong objectOwner, ulong sender, string methodName, int i, bool b, float f, string s)
Parameters
VerifySentToNotMeWithReceivedFrom(ulong, ulong, string)
Declaration
public void VerifySentToNotMeWithReceivedFrom(ulong objectOwner, ulong sender, string methodName)
Parameters
VerifySentToNotOwner(ulong, ulong, string)
Declaration
public void VerifySentToNotOwner(ulong objectOwner, ulong sender, string methodName)
Parameters
VerifySentToNotOwnerWithParams(ulong, ulong, string, int, bool, float, string)
Declaration
public void VerifySentToNotOwnerWithParams(ulong objectOwner, ulong sender, string methodName, int i, bool b, float f, string s)
Parameters
VerifySentToNotOwnerWithReceivedFrom(ulong, ulong, string)
Declaration
public void VerifySentToNotOwnerWithReceivedFrom(ulong objectOwner, ulong sender, string methodName)
Parameters
VerifySentToNotServer(ulong, ulong, string)
Declaration
public void VerifySentToNotServer(ulong objectOwner, ulong sender, string methodName)
Parameters
VerifySentToNotServerWithParams(ulong, ulong, string, int, bool, float, string)
Declaration
public void VerifySentToNotServerWithParams(ulong objectOwner, ulong sender, string methodName, int i, bool b, float f, string s)
Parameters
VerifySentToNotServerWithReceivedFrom(ulong, ulong, string)
Declaration
public void VerifySentToNotServerWithReceivedFrom(ulong objectOwner, ulong sender, string methodName)
Parameters
VerifySentToOwner(ulong, ulong, string)
Declaration
public void VerifySentToOwner(ulong objectOwner, ulong sender, string methodName)
Parameters
VerifySentToOwnerWithParams(ulong, ulong, string, int, bool, float, string)
Declaration
public void VerifySentToOwnerWithParams(ulong objectOwner, ulong sender, string methodName, int i, bool b, float f, string s)
Parameters
VerifySentToOwnerWithReceivedFrom(ulong, ulong, string)
Declaration
public void VerifySentToOwnerWithReceivedFrom(ulong objectOwner, ulong sender, string methodName)
Parameters
VerifySentToServer(ulong, ulong, string)
Declaration
public void VerifySentToServer(ulong objectOwner, ulong sender, string methodName)
Parameters
VerifySentToServerWithParams(ulong, ulong, string, int, bool, float, string)
Declaration
public void VerifySentToServerWithParams(ulong objectOwner, ulong sender, string methodName, int i, bool b, float f, string s)
Parameters
VerifySentToServerWithReceivedFrom(ulong, ulong, string)
Declaration
public void VerifySentToServerWithReceivedFrom(ulong objectOwner, ulong sender, string methodName)
Parameters