From 7d30f5ce1ee1edb4aaaef48ec70cc072b4c357a5 Mon Sep 17 00:00:00 2001 From: KloopRE <100780612+KloopRE@users.noreply.github.com> Date: Tue, 26 May 2026 20:34:19 +0300 Subject: [PATCH] Enhance entity deletion test to ignore timed despawn entities (#44077) * Enhance entity deletion test with extra ticks * Implement CleanupTransientEntities for test stability Added CleanupTransientEntities method to handle deletion of transient side-effect entities during tests. * Add using directive for Robust.Shared.Spawners * corrections --- Content.IntegrationTests/Tests/EntityTest.cs | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Content.IntegrationTests/Tests/EntityTest.cs b/Content.IntegrationTests/Tests/EntityTest.cs index c82535dd36..59164972c7 100644 --- a/Content.IntegrationTests/Tests/EntityTest.cs +++ b/Content.IntegrationTests/Tests/EntityTest.cs @@ -13,6 +13,7 @@ using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Prototypes; using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.Spawners; namespace Content.IntegrationTests.Tests { @@ -290,6 +291,8 @@ namespace Content.IntegrationTests.Tests // If the entity deleted itself, check that it didn't spawn other entities if (!server.EntMan.EntityExists(uid)) { + await CleanupTransientEntities(pair, serverEntities); + Assert.That(Count(server.EntMan), Is.EqualTo(count), $"Server prototype {protoId} failed on deleting itself\n" + BuildDiffString(serverEntities, Entities(server.EntMan), server.EntMan)); Assert.That(Count(client.EntMan), Is.EqualTo(clientCount), $"Client prototype {protoId} failed on deleting itself\n" + @@ -309,6 +312,7 @@ namespace Content.IntegrationTests.Tests await server.WaitPost(() => server.EntMan.DeleteEntity(uid)); await pair.RunTicksSync(3); + await CleanupTransientEntities(pair, serverEntities); // Check that the number of entities has gone back to the original value. Assert.That(Count(server.EntMan), Is.EqualTo(count), $"Server prototype {protoId} failed on deletion: count didn't reset properly\n" + @@ -321,6 +325,33 @@ namespace Content.IntegrationTests.Tests }); } + /// + /// Deletes any entities with that were not present in the baseline snapshot. + /// Some entities spawn transient side-effects on deletion (e.g. explosion visuals). These side-effect entities + /// use TimedDespawn and would persist across test iterations, corrupting baseline entity counts and causing + /// cascading assertion failures. + /// + private static async Task CleanupTransientEntities(Pair.TestPair pair, HashSet baselineEntities) + { + var server = pair.Server; + await server.WaitPost(() => + { + var toRemove = new List(); + var query = server.EntMan.AllEntityQueryEnumerator(); + while (query.MoveNext(out var uid, out _)) + { + if (!baselineEntities.Contains(uid)) + toRemove.Add(uid); + } + + foreach (var uid in toRemove) + { + server.EntMan.DeleteEntity(uid); + } + }); + await pair.RunTicksSync(3); + } + private static string BuildDiffString(IEnumerable oldEnts, IEnumerable newEnts, IEntityManager entMan) { var sb = new StringBuilder();