Skip to content

Commit 3afc6f9

Browse files
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.
1 parent da4649e commit 3afc6f9

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTest.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ public abstract class NetcodeIntegrationTest
2424
/// Used to determine if a NetcodeIntegrationTest is currently running to
2525
/// determine how clients will load scenes
2626
/// </summary>
27+
protected const float k_DefaultTimeoutPeriod = 8.0f;
28+
protected const float k_TickFrequency = 1.0f / k_DefaultTickRate;
2729
internal static bool IsRunning { get; private set; }
28-
29-
protected static TimeoutHelper s_GlobalTimeoutHelper = new TimeoutHelper(8.0f);
30-
protected static WaitForSecondsRealtime s_DefaultWaitForTick = new WaitForSecondsRealtime(1.0f / k_DefaultTickRate);
30+
protected static TimeoutHelper s_GlobalTimeoutHelper = new TimeoutHelper(k_DefaultTimeoutPeriod);
31+
protected static WaitForSecondsRealtime s_DefaultWaitForTick = new WaitForSecondsRealtime(k_TickFrequency);
3132

3233
public NetcodeLogAssert NetcodeLogAssert;
3334
public enum SceneManagementState

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ namespace Unity.Netcode.RuntimeTests
1212
internal class NetworkObjectSpawnManyObjectsTests : NetcodeIntegrationTest
1313
{
1414
protected override int NumberOfClients => 1;
15-
// "many" in this case means enough to exceed a ushort_max message size written in the header
16-
// 1500 is not a magic number except that it's big enough to trigger a failure
1715
private const int k_SpawnedObjects = 1500;
1816

1917
private NetworkPrefab m_PrefabToSpawn;
@@ -52,19 +50,23 @@ protected override void OnServerAndClientsCreated()
5250
}
5351

5452
[UnityTest]
55-
// When this test fails it does so without an exception and will wait the default ~6 minutes
56-
[Timeout(10000)]
5753
public IEnumerator WhenManyObjectsAreSpawnedAtOnce_AllAreReceived()
5854
{
55+
var timeStarted = Time.realtimeSinceStartup;
5956
for (int x = 0; x < k_SpawnedObjects; x++)
6057
{
6158
NetworkObject serverObject = Object.Instantiate(m_PrefabToSpawn.Prefab).GetComponent<NetworkObject>();
6259
serverObject.NetworkManagerOwner = m_ServerNetworkManager;
6360
serverObject.Spawn();
6461
}
62+
63+
var timeSpawned = Time.realtimeSinceStartup - timeStarted;
64+
// Provide plenty of time to spawn all 1500 objects in case the CI VM is running slow
65+
var timeoutHelper = new TimeoutHelper(30);
6566
// ensure all objects are replicated
66-
yield return WaitForConditionOrTimeOut(() => SpawnObjecTrackingComponent.SpawnedObjects == k_SpawnedObjects);
67-
AssertOnTimeout($"Timed out waiting for the client to spawn {k_SpawnedObjects} objects!");
67+
yield return WaitForConditionOrTimeOut(() => SpawnObjecTrackingComponent.SpawnedObjects == k_SpawnedObjects, timeoutHelper);
68+
69+
AssertOnTimeout($"Timed out waiting for the client to spawn {k_SpawnedObjects} objects! Time to spawn: {timeSpawned} | Time to timeout: {timeStarted - Time.realtimeSinceStartup}", timeoutHelper);
6870
}
6971
}
7072
}

0 commit comments

Comments
 (0)