From 45c4bfc447291a41f836ad12f688006cf91df7a1 Mon Sep 17 00:00:00 2001 From: Marty Date: Wed, 22 Oct 2025 04:45:36 +0300 Subject: [PATCH] ent test omu --- Content.IntegrationTests/Tests/EntityTest.cs | 93 ++++++++++++++++++-- 1 file changed, 88 insertions(+), 5 deletions(-) diff --git a/Content.IntegrationTests/Tests/EntityTest.cs b/Content.IntegrationTests/Tests/EntityTest.cs index 83e6e99b6e9..fe52fd7f5d6 100644 --- a/Content.IntegrationTests/Tests/EntityTest.cs +++ b/Content.IntegrationTests/Tests/EntityTest.cs @@ -75,7 +75,7 @@ public sealed class EntityTest { private static readonly ProtoId SpawnerCategory = "Spawner"; - [Test] + [Test, NonParallelizable] // Goobstation edit - NonParallelizable public async Task SpawnAndDeleteAllEntitiesOnDifferentMaps() { // This test dirties the pair as it simply deletes ALL entities when done. Overhead of restarting the round @@ -89,8 +89,22 @@ public async Task SpawnAndDeleteAllEntitiesOnDifferentMaps() var prototypeMan = server.ResolveDependency(); var mapSystem = entityMan.System(); + // Goobstation edit start - moved this up and out of server.WaitPost + var protoIds = prototypeMan + .EnumeratePrototypes() + .Where(p => !p.Abstract) + .Where(p => !pair.IsTestPrototype(p)) + .Where(p => !p.Components.ContainsKey("MapGrid")) // This will smash stuff otherwise. + .Where(p => !p.Components.ContainsKey("MobReplacementRule")) // goob edit - fuck them mimics + .Where(p => !p.Components.ContainsKey("Supermatter")) // Goobstation - Supermatter eats everything, oh no! + .Where(p => !p.Components.ContainsKey("RoomFill")) // This comp can delete all entities, and spawn others + .Select(p => p.ID) + .ToList(); + // Goobstation edit end + await server.WaitPost(() => { + /* Goobstation var protoIds = prototypeMan .EnumeratePrototypes() .Where(p => !p.Abstract) @@ -101,6 +115,7 @@ await server.WaitPost(() => .Where(p => !p.Components.ContainsKey("RoomFill")) // This comp can delete all entities, and spawn others .Select(p => p.ID) .ToList(); + Goobstation */ foreach (var protoId in protoIds) { @@ -113,7 +128,41 @@ await server.WaitPost(() => } }); - await server.WaitRunTicks(15); + // Goobstation Edit Start (this test isn't even worth the effort tbh) + // Run up to 15 ticks, but stop early if memory usage exceeds 13 GB + // At the time of writing (2025-10-22) Wizden reaches at most like 9-10 GB on SpawnAndDirtyAllEntities + // Goob gets to about ~12GB, if we reach 16 GB on integrationtests we'll time out from GitHub + // + // This area on my local testing is where most of the memory builds up, so run it as long as we can within reason. + // i mean yeah you could run the test in batches of entities but its not really a stress test then is it. + + const int maxTicks = 15; // (default wizden) + const long memoryLimitBytes = 13L * 1024 * 1024 * 1024; // 13 GB, depends on how close you wanna fly to the sun. + + var warninglog = true; // if we stop caring about this test turn this off. + + for (var tick = 0; tick < maxTicks; tick++) + { + await pair.RunTicksSync(1); + + var memoryUsed = GC.GetTotalMemory(forceFullCollection: false); + + // debug logging but tbh just use debugger + // await TestContext.Progress.WriteLineAsync($"[EntityTest SpawnAndDeleteAllEntitiesOnDifferentMaps] Memory usage = {memoryUsed / (1024 * 1024 * 1024.0):F2} GB at tick {tick + 1}"); + + if (memoryUsed < memoryLimitBytes) + continue; + if (warninglog) + await TestContext.Progress.WriteLineAsync( + "Warning:\n"+ + $"[SpawnAndDeleteAllEntitiesOnDifferentMaps] Memory usage reached {memoryUsed / (1024 * 1024 * 1024.0):F2} GB at tick {tick + 1} out of {maxTicks} \n" + + "Stopping early (limit: 13 GB)." + + $"\nWe spawned a total of {protoIds.Count} entities and held on for {tick+1} ticks. We're probably fine." + ); + + break; // stop ticking early + } + // Goobstation Edit End await server.WaitPost(() => { @@ -202,7 +251,7 @@ await server.WaitPost(() => /// Variant of that also launches a client and dirties /// all components on every entity. /// - [Test] + [Test, NonParallelizable] // Goobstation edit - NonParallelizable public async Task SpawnAndDirtyAllEntities() { // This test dirties the pair as it simply deletes ALL entities when done. Overhead of restarting the round @@ -244,7 +293,41 @@ await server.WaitPost(() => } }); - await pair.RunTicksSync(15); + // Goobstation Edit Start (this test isn't even worth the effort tbh) + // Run up to 15 ticks, but stop early if memory usage exceeds 13 GB + // At the time of writing (2025-10-22) Wizden reaches at most like 9-10 GB on this test + // Goob gets to about 15GB, if we reach 16 GB on integrationtests we'll time out from github + // + // This area on my local testing is where most of the memory builds up, so run it as long as we can within reason. + // i mean yeah you could run the test in batches of entities but its not really a stress test then is it. + + const int maxTicks = 15; // (default wizden) + const long memoryLimitBytes = 13L * 1024 * 1024 * 1024; // 13 GB + + var warninglog = true; // if we stop caring about this test turn this off. + + for (var tick = 0; tick < maxTicks; tick++) + { + await pair.RunTicksSync(1); + + var memoryUsed = GC.GetTotalMemory(forceFullCollection: false); + + // debug logging but tbh just use debugger + // await TestContext.Progress.WriteLineAsync($"[EntityTest SpawnAndDirtyAllEntities] Memory usage = {memoryUsed / (1024 * 1024 * 1024.0):F2} GB at tick {tick + 1}"); + + if (memoryUsed < memoryLimitBytes) + continue; + if (warninglog) + await TestContext.Progress.WriteLineAsync( + "Warning:\n"+ + $"[SpawnAndDirtyAllEntities] Memory usage reached {memoryUsed / (1024 * 1024 * 1024.0):F2} GB at tick {tick + 1} out of {maxTicks}\n" + + "Stopping early (limit: 13 GB)." + + $"\nWe spawned and dirtied {protoIds.Count} entities and held on for {tick+1} ticks. We're probably fine." + ); + + break; // stop ticking early + } + // Goobstation Edit End // Make sure the client actually received the entities // 500 is completely arbitrary. Note that the client & sever entity counts aren't expected to match. @@ -516,4 +599,4 @@ await server.WaitAssertion(() => await pair.CleanReturnAsync(); } } -} \ No newline at end of file +}