Skip to content

Commit 2a5de93

Browse files
fix: PlayerSpawnObjectVisibilityTests test instability [Up-Port] (#3548)
This PR addresses some v2.x test instabilities that includes: - An up-port of #3547. - A fix for the `InterpolationStopAndStartMotionTest` instabilities. - A fix for the `BuildTests.BasicBuildTest` instabilities. [MTT-12645](https://jira.unity3d.com/browse/MTT-12645) ## Changelog NA ## Testing and Documentation - Includes integration test modifications. - No documentation changes or additions were necessary. <!-- Uncomment and mark items off with a * if this PR deprecates any API: ### Deprecated API - [ ] An `[Obsolete]` attribute was added along with a `(RemovedAfter yyyy-mm-dd)` entry. - [ ] An [api updater] was added. - [ ] Deprecation of the API is explained in the CHANGELOG. - [ ] The users can understand why this API was removed and what they should use instead. --> ## Backport This is an up-port of #3547. <!-- If this is a backport: - Add the following to the PR title: "\[Backport\] ..." . - Link to the original PR. If this needs a backport - state this here If a backport is not needed please provide the reason why. If the "Backports" section is not present it will lead to a CI test failure. -->
1 parent 1de6174 commit 2a5de93

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

com.unity.netcode.gameobjects/Tests/Editor/Build/BuildTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ internal class BuildTests
1212
{
1313
public const string DefaultBuildScenePath = "Tests/Editor/Build/BuildTestScene.unity";
1414

15+
// Increased the Build test timeout from 3 to 10 minutes.
16+
[Timeout(900000)]
1517
[Test]
1618
public void BasicBuildTest()
1719
{

com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/PlayerSpawnObjectVisibilityTests.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,25 @@ protected override void OnCreatePlayerPrefab()
6363
base.OnCreatePlayerPrefab();
6464
}
6565

66+
/// <summary>
67+
/// Bypassing this on v1.x as the deferred show message could be processed on the next
68+
/// frame from when the client registers having connected.
69+
/// </summary>
70+
protected override bool ShouldWaitForNewClientToConnect(NetworkManager networkManager)
71+
{
72+
return false;
73+
}
74+
75+
/// <summary>
76+
/// Validate that the player object is spawned on the client side.
77+
/// </summary>
78+
/// <returns></returns>
79+
private bool ClientSpawnedPlayer()
80+
{
81+
var playerObject = m_ClientNetworkManagers[0].LocalClient.PlayerObject;
82+
return playerObject != null && playerObject.IsSpawned && playerObject.IsOwner;
83+
}
84+
6685
/// <summary>
6786
/// Tests the scenario where under a client-server network topology if a player prefab
6887
/// is spawned by the server with no observers but the player prefab itself has server
@@ -81,7 +100,17 @@ public IEnumerator NetworkShowOnSpawnTest([Values] PlayerSpawnStages spawnStage)
81100

82101
yield return CreateAndStartNewClient();
83102

84-
yield return new WaitForSeconds(0.25f);
103+
// Wait for the new client to connect
104+
yield return WaitForClientsConnectedOrTimeOut();
105+
AssertOnTimeout($"Timed out waiting for client to connect!");
106+
OnNewClientStartedAndConnected(m_ClientNetworkManagers[0]);
107+
108+
// Wait for the new client to have spawned the player
109+
yield return WaitForConditionOrTimeOut(ClientSpawnedPlayer);
110+
AssertOnTimeout($"Timed out waiting for client to spawn its player object!");
111+
112+
// Provide some time to assure there are no additional attempts to spawn the same instance
113+
yield return new WaitForSeconds(0.5f);
85114

86115
NetcodeLogAssert.LogWasNotReceived(LogType.Warning, new Regex("but it is already in the spawned list!"));
87116
var client = GetNonAuthorityNetworkManager();

com.unity.netcode.gameobjects/Tests/Runtime/NetworkTransform/InterpolationStopAndStartMotionTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ public override void OnUpdate()
270270
// Add it to the table of state updates
271271
var stateEntry = new StateEntry()
272272
{
273-
TimeAdded = Time.realtimeSinceStartup,
273+
// Use the server time to get the valid "relative" time since the session started.
274+
TimeAdded = NetworkManager.ServerTime.TimeAsFloat,
274275
State = m_PosInterpolator.InterpolateState,
275276
};
276277

0 commit comments

Comments
 (0)