Improve test stability (#10913)
This commit is contained in:
@@ -766,6 +766,7 @@ public sealed class PairTracker : IAsyncDisposable
|
||||
{
|
||||
Pair.Client.Dispose();
|
||||
Pair.Server.Dispose();
|
||||
await PoolManager.ReallyBeIdle(Pair);
|
||||
var returnTime2 = cleanWatch.Elapsed;
|
||||
await TestContext.Out.WriteLineAsync($"{nameof(CleanReturnAsync)}: Clean disposed in {returnTime2.TotalMilliseconds} ms");
|
||||
return;
|
||||
|
||||
@@ -6,6 +6,7 @@ using Content.Shared.CCVar;
|
||||
using Content.Shared.Coordinates;
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
@@ -18,79 +19,89 @@ namespace Content.IntegrationTests.Tests
|
||||
public sealed class EntityTest
|
||||
{
|
||||
[Test]
|
||||
public async Task SpawnTest()
|
||||
public async Task SpawnAndDeleteAllEntitiesOnDifferentMaps()
|
||||
{
|
||||
//TODO: Run this test in a for loop, and figure out why garbage is ending up in the Entities list on cleanup.
|
||||
//If this gets fixed, see also UninitializedSaveTest.
|
||||
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, Dirty = true, Destructive = true});
|
||||
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, Destructive = true});
|
||||
var server = pairTracker.Pair.Server;
|
||||
|
||||
var mapManager = server.ResolveDependency<IMapManager>();
|
||||
var entityMan = server.ResolveDependency<IEntityManager>();
|
||||
var prototypeMan = server.ResolveDependency<IPrototypeManager>();
|
||||
var tileDefinitionManager = server.ResolveDependency<ITileDefinitionManager>();
|
||||
IEntityManager entityMan = null;
|
||||
|
||||
var prototypes = new List<EntityPrototype>();
|
||||
IMapGrid grid = default;
|
||||
EntityUid testEntity;
|
||||
|
||||
//Build up test environment
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
// Create a one tile grid to stave off the grid 0 monsters
|
||||
entityMan = IoCManager.Resolve<IEntityManager>();
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
var prototypeMan = IoCManager.Resolve<IPrototypeManager>();
|
||||
var protoIds = prototypeMan
|
||||
.EnumeratePrototypes<EntityPrototype>()
|
||||
.Where(p=>!p.Abstract)
|
||||
.Select(p => p.ID)
|
||||
.ToList();
|
||||
foreach (var protoId in protoIds)
|
||||
{
|
||||
var mapId = mapManager.CreateMap();
|
||||
|
||||
mapManager.AddUninitializedMap(mapId);
|
||||
|
||||
grid = mapManager.CreateGrid(mapId);
|
||||
|
||||
var tileDefinition = tileDefinitionManager["UnderPlating"];
|
||||
var tile = new Tile(tileDefinition.TileId);
|
||||
var coordinates = grid.ToCoordinates();
|
||||
|
||||
grid.SetTile(coordinates, tile);
|
||||
|
||||
mapManager.DoMapInitialize(mapId);
|
||||
var grid = mapManager.CreateGrid(mapId);
|
||||
var coord = new EntityCoordinates(grid.GridEntityId, 0, 0);
|
||||
entityMan.SpawnEntity(protoId, coord);
|
||||
}
|
||||
});
|
||||
|
||||
await server.WaitRunTicks(5);
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
var testLocation = grid.ToCoordinates();
|
||||
|
||||
//Generate list of non-abstract prototypes to test
|
||||
foreach (var prototype in prototypeMan.EnumeratePrototypes<EntityPrototype>())
|
||||
var entityMetas = entityMan.EntityQuery<MetaDataComponent>().ToList();
|
||||
foreach (var meta in entityMetas)
|
||||
{
|
||||
if (prototype.Abstract)
|
||||
{
|
||||
continue;
|
||||
if(!entityMan.Deleted(meta.Owner))
|
||||
entityMan.DeleteEntity(meta.Owner);
|
||||
}
|
||||
|
||||
prototypes.Add(prototype);
|
||||
}
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
//Iterate list of prototypes to spawn
|
||||
foreach (var prototype in prototypes)
|
||||
{
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
Logger.LogS(LogLevel.Debug, "EntityTest", $"Testing: {prototype.ID}");
|
||||
testEntity = entityMan.SpawnEntity(prototype.ID, testLocation);
|
||||
server.RunTicks(1);
|
||||
if(!entityMan.Deleted(testEntity))
|
||||
entityMan.DeleteEntity(testEntity);
|
||||
}, "Entity '{0}' threw an exception.",
|
||||
prototype.ID);
|
||||
}
|
||||
Assert.That(entityMan.EntityCount, Is.Zero);
|
||||
});
|
||||
});
|
||||
|
||||
await pairTracker.CleanReturnAsync();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SpawnAndDeleteAllEntitiesInTheSameSpot()
|
||||
{
|
||||
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, Destructive = true});
|
||||
var server = pairTracker.Pair.Server;
|
||||
|
||||
IEntityManager entityMan = null;
|
||||
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
entityMan = IoCManager.Resolve<IEntityManager>();
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
|
||||
var prototypeMan = IoCManager.Resolve<IPrototypeManager>();
|
||||
var protoIds = prototypeMan
|
||||
.EnumeratePrototypes<EntityPrototype>()
|
||||
.Where(p=>!p.Abstract)
|
||||
.Select(p => p.ID)
|
||||
.ToList();
|
||||
var mapId = mapManager.CreateMap();
|
||||
var grid = mapManager.CreateGrid(mapId);
|
||||
var coord = new EntityCoordinates(grid.GridEntityId, 0, 0);
|
||||
foreach (var protoId in protoIds)
|
||||
{
|
||||
entityMan.SpawnEntity(protoId, coord);
|
||||
}
|
||||
});
|
||||
await server.WaitRunTicks(5);
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
var entityMetas = entityMan.EntityQuery<MetaDataComponent>().ToList();
|
||||
foreach (var meta in entityMetas)
|
||||
{
|
||||
if(!entityMan.Deleted(meta.Owner))
|
||||
entityMan.DeleteEntity(meta.Owner);
|
||||
}
|
||||
|
||||
Assert.That(entityMan.EntityCount, Is.Zero);
|
||||
});
|
||||
await pairTracker.CleanReturnAsync();
|
||||
}
|
||||
[Test]
|
||||
public async Task AllComponentsOneToOneDeleteTest()
|
||||
{
|
||||
|
||||
@@ -445,10 +445,11 @@ namespace Content.Server.AI.Pathfinding.Accessible
|
||||
var parentChunk = node.ParentChunk;
|
||||
|
||||
// No guarantee the node even has a region yet (if we're doing neighbor lookups)
|
||||
if (!_regions[parentChunk.GridId].TryGetValue(parentChunk, out var regions))
|
||||
{
|
||||
if (!_regions.TryGetValue(parentChunk.GridId, out var chunk))
|
||||
return null;
|
||||
|
||||
if (!chunk.TryGetValue(parentChunk, out var regions))
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (var region in regions)
|
||||
{
|
||||
|
||||
@@ -19,6 +19,8 @@ public sealed partial class TriggerSystem
|
||||
//Ensures the entity trigger will have an active component
|
||||
EnsureComp<ActiveTriggerOnTimedCollideComponent>(uid);
|
||||
var otherUID = args.OtherFixture.Body.Owner;
|
||||
if (component.Colliding.ContainsKey(otherUID))
|
||||
return;
|
||||
component.Colliding.Add(otherUID, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,8 @@ public sealed class StationSystem : EntitySystem
|
||||
private void OnStationDeleted(EntityUid uid, StationDataComponent component, ComponentShutdown args)
|
||||
{
|
||||
if (_stations.Contains(uid) && // Was not deleted via DeleteStation()
|
||||
_gameTicker.RunLevel == GameRunLevel.InRound) // And not due to a round restart
|
||||
_gameTicker.RunLevel == GameRunLevel.InRound && // And not due to a round restart
|
||||
_gameTicker.LobbyEnabled) // If there isn't a lobby, this is probably sandbox, single player, or a test
|
||||
{
|
||||
// printing a stack trace, rather than throwing an exception so that entity deletion continues as normal.
|
||||
Logger.Error($"Station entity {ToPrettyString(uid)} is getting deleted mid-round. Trace: {Environment.StackTrace}");
|
||||
|
||||
@@ -395,7 +395,8 @@ namespace Content.Shared.Body.Components
|
||||
var gibs = new HashSet<EntityUid>();
|
||||
foreach (var part in SlotParts.Keys)
|
||||
{
|
||||
if (!metaQuery.HasComponent(part.Owner))
|
||||
if (!metaQuery.TryGetComponent(part.Owner, out var meta) ||
|
||||
meta.EntityLifeStage >= EntityLifeStage.Terminating)
|
||||
{
|
||||
SlotParts.Remove(part);
|
||||
continue;
|
||||
|
||||
@@ -94,6 +94,7 @@
|
||||
tags:
|
||||
- Debug
|
||||
- type: Clickable
|
||||
- type: PowerNetworkBattery
|
||||
- type: InteractionOutline
|
||||
- type: Physics
|
||||
- type: Fixtures
|
||||
|
||||
Reference in New Issue
Block a user