From 3afc6f90435f3c61061ecbaeaac6a3b18cef73eb Mon Sep 17 00:00:00 2001 From: Noel Stephens Date: Tue, 17 Sep 2024 16:01:07 -0500 Subject: [PATCH] fix: spawn many objects apv failures (#3069) * update Minor update to some const values * test Adjusting test to handle slower CI VMs as well as logging additional information regarding the time it took to spawn vs the total time the test took. --- .../TestHelpers/Runtime/NetcodeIntegrationTest.cs | 7 ++++--- .../NetworkObjectSpawnManyObjectsTests.cs | 14 ++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTest.cs b/com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTest.cs index 70ed7842f5..159d923d69 100644 --- a/com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTest.cs +++ b/com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTest.cs @@ -24,10 +24,11 @@ public abstract class NetcodeIntegrationTest /// Used to determine if a NetcodeIntegrationTest is currently running to /// determine how clients will load scenes /// + protected const float k_DefaultTimeoutPeriod = 8.0f; + protected const float k_TickFrequency = 1.0f / k_DefaultTickRate; internal static bool IsRunning { get; private set; } - - protected static TimeoutHelper s_GlobalTimeoutHelper = new TimeoutHelper(8.0f); - protected static WaitForSecondsRealtime s_DefaultWaitForTick = new WaitForSecondsRealtime(1.0f / k_DefaultTickRate); + protected static TimeoutHelper s_GlobalTimeoutHelper = new TimeoutHelper(k_DefaultTimeoutPeriod); + protected static WaitForSecondsRealtime s_DefaultWaitForTick = new WaitForSecondsRealtime(k_TickFrequency); public NetcodeLogAssert NetcodeLogAssert; public enum SceneManagementState diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectSpawnManyObjectsTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectSpawnManyObjectsTests.cs index 7c8b1370e4..b80e055f0f 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectSpawnManyObjectsTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectSpawnManyObjectsTests.cs @@ -12,8 +12,6 @@ namespace Unity.Netcode.RuntimeTests internal class NetworkObjectSpawnManyObjectsTests : NetcodeIntegrationTest { protected override int NumberOfClients => 1; - // "many" in this case means enough to exceed a ushort_max message size written in the header - // 1500 is not a magic number except that it's big enough to trigger a failure private const int k_SpawnedObjects = 1500; private NetworkPrefab m_PrefabToSpawn; @@ -52,19 +50,23 @@ protected override void OnServerAndClientsCreated() } [UnityTest] - // When this test fails it does so without an exception and will wait the default ~6 minutes - [Timeout(10000)] public IEnumerator WhenManyObjectsAreSpawnedAtOnce_AllAreReceived() { + var timeStarted = Time.realtimeSinceStartup; for (int x = 0; x < k_SpawnedObjects; x++) { NetworkObject serverObject = Object.Instantiate(m_PrefabToSpawn.Prefab).GetComponent(); serverObject.NetworkManagerOwner = m_ServerNetworkManager; serverObject.Spawn(); } + + var timeSpawned = Time.realtimeSinceStartup - timeStarted; + // Provide plenty of time to spawn all 1500 objects in case the CI VM is running slow + var timeoutHelper = new TimeoutHelper(30); // ensure all objects are replicated - yield return WaitForConditionOrTimeOut(() => SpawnObjecTrackingComponent.SpawnedObjects == k_SpawnedObjects); - AssertOnTimeout($"Timed out waiting for the client to spawn {k_SpawnedObjects} objects!"); + yield return WaitForConditionOrTimeOut(() => SpawnObjecTrackingComponent.SpawnedObjects == k_SpawnedObjects, timeoutHelper); + + AssertOnTimeout($"Timed out waiting for the client to spawn {k_SpawnedObjects} objects! Time to spawn: {timeSpawned} | Time to timeout: {timeStarted - Time.realtimeSinceStartup}", timeoutHelper); } } }