Skip to content

Commit 83f641b

Browse files
fix: PlayerSpawnObjectVisibilityTests test instability (#3547)
Adjusting the PlayerSpawnObjectVisibilityTests so that it provides some additional time for the deferred NetworkShow message to be processed. [MTT-12639](https://jira.unity3d.com/browse/MTT-12639) ## Changelog NA ## Testing and Documentation - Includes integration test adjustments. - No documentation changes or additions were necessary. ## Backport No up-port is needed as this appears to be specific to v1.x.
1 parent afdedc0 commit 83f641b

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace Unity.Netcode.RuntimeTests
1313
internal class PlayerSpawnObjectVisibilityTests : NetcodeIntegrationTest
1414
{
1515
protected override int NumberOfClients => 0;
16-
1716
public enum PlayerSpawnStages
1817
{
1918
OnNetworkSpawn,
@@ -63,6 +62,25 @@ protected override void OnCreatePlayerPrefab()
6362
base.OnCreatePlayerPrefab();
6463
}
6564

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

82100
yield return CreateAndStartNewClient();
83101

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

86114
NetcodeLogAssert.LogWasNotReceived(LogType.Warning, new Regex("but it is already in the spawned list!"));
87115
var client = m_ClientNetworkManagers[0];

0 commit comments

Comments
 (0)