Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 88 additions & 5 deletions Content.IntegrationTests/Tests/EntityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public sealed class EntityTest
{
private static readonly ProtoId<EntityCategoryPrototype> 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
Expand All @@ -89,8 +89,22 @@ public async Task SpawnAndDeleteAllEntitiesOnDifferentMaps()
var prototypeMan = server.ResolveDependency<IPrototypeManager>();
var mapSystem = entityMan.System<SharedMapSystem>();

// Goobstation edit start - moved this up and out of server.WaitPost
var protoIds = prototypeMan
.EnumeratePrototypes<EntityPrototype>()
.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<EntityPrototype>()
.Where(p => !p.Abstract)
Expand All @@ -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)
{
Expand All @@ -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(() =>
{
Expand Down Expand Up @@ -202,7 +251,7 @@ await server.WaitPost(() =>
/// Variant of <see cref="SpawnAndDeleteAllEntitiesOnDifferentMaps"/> that also launches a client and dirties
/// all components on every entity.
/// </summary>
[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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -516,4 +599,4 @@ await server.WaitAssertion(() =>
await pair.CleanReturnAsync();
}
}
}
}
Loading