Skip to content

Commit

Permalink
fix: spawn many objects apv failures (#3069)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
NoelStephensUnity authored Sep 17, 2024
1 parent da4649e commit 3afc6f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ public abstract class NetcodeIntegrationTest
/// Used to determine if a NetcodeIntegrationTest is currently running to
/// determine how clients will load scenes
/// </summary>
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<NetworkObject>();
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);
}
}
}

0 comments on commit 3afc6f9

Please sign in to comment.