Fix content.integration tests warnings (#17817)

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
TemporalOroboros
2023-07-05 21:54:25 -07:00
committed by GitHub
parent 20c1754abd
commit ba91023a85
121 changed files with 3658 additions and 1961 deletions

View File

@@ -1,11 +1,8 @@
using System.Threading.Tasks;
using Content.Server.Body.Systems;
using Content.Server.Body.Systems;
using Content.Shared.Body.Components;
using Content.Shared.Body.Part;
using Content.Shared.Rotation;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
@@ -31,24 +28,34 @@ namespace Content.IntegrationTests.Tests.Body
public async Task RemoveLegsFallTest()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
{NoClient = true, ExtraPrototypes = Prototypes});
{
NoClient = true,
ExtraPrototypes = Prototypes
});
var server = pairTracker.Pair.Server;
EntityUid human = default!;
AppearanceComponent appearance = null;
var entityManager = server.ResolveDependency<IEntityManager>();
var mapManager = server.ResolveDependency<IMapManager>();
var appearanceSystem = entityManager.System<SharedAppearanceSystem>();
await server.WaitAssertion(() =>
{
var mapId = mapManager.CreateMap();
BodyComponent body = null;
var human = entityManager.SpawnEntity("HumanBodyAndAppearanceDummy",
human = entityManager.SpawnEntity("HumanBodyAndAppearanceDummy",
new MapCoordinates(Vector2.Zero, mapId));
Assert.That(entityManager.TryGetComponent(human, out BodyComponent body));
Assert.That(entityManager.TryGetComponent(human, out appearance));
Assert.Multiple(() =>
{
Assert.That(entityManager.TryGetComponent(human, out body));
Assert.That(entityManager.TryGetComponent(human, out appearance));
});
Assert.That(!appearance.TryGetData(RotationVisuals.RotationState, out RotationState _));
Assert.That(!appearanceSystem.TryGetData(human, RotationVisuals.RotationState, out RotationState _, appearance));
var bodySystem = entityManager.System<BodySystem>();
var legs = bodySystem.GetBodyChildrenOfType(human, BodyPartType.Leg, body);
@@ -61,8 +68,11 @@ namespace Content.IntegrationTests.Tests.Body
await server.WaitAssertion(() =>
{
Assert.That(appearance.TryGetData(RotationVisuals.RotationState, out RotationState state));
#pragma warning disable NUnit2045
// Interdependent assertions.
Assert.That(appearanceSystem.TryGetData(human, RotationVisuals.RotationState, out RotationState state, appearance));
Assert.That(state, Is.EqualTo(RotationState.Horizontal));
#pragma warning restore NUnit2045
});
await pairTracker.CleanReturnAsync();
}

View File

@@ -1,16 +1,16 @@
using System.Threading.Tasks;
using Content.Server.Atmos.Components;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Body.Components;
using Content.Server.Body.Systems;
using Content.Shared.Body.Components;
using NUnit.Framework;
using Robust.Server.GameObjects;
using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Maths;
using System.Linq;
namespace Content.IntegrationTests.Tests.Body
{
@@ -52,7 +52,10 @@ namespace Content.IntegrationTests.Tests.Body
{
// --- Setup
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
{NoClient = true, ExtraPrototypes = Prototypes});
{
NoClient = true,
ExtraPrototypes = Prototypes
});
var server = pairTracker.Pair.Server;
await server.WaitIdleAsync();
@@ -68,17 +71,22 @@ namespace Content.IntegrationTests.Tests.Body
BodyComponent body = default;
EntityUid human = default;
GridAtmosphereComponent relevantAtmos = default;
float startingMoles = 0.0f;
var startingMoles = 0.0f;
var testMapName = "Maps/Test/Breathing/3by3-20oxy-80nit.yml";
await server.WaitPost(() =>
{
mapId = mapManager.CreateMap();
grid = mapLoader.LoadGrid(mapId, testMapName);
Assert.That(mapLoader.TryLoad(mapId, testMapName, out var roots));
var query = entityManager.GetEntityQuery<MapGridComponent>();
var grids = roots.Where(x => query.HasComponent(x));
Assert.That(grids, Is.Not.Empty);
grid = grids.First();
});
Assert.NotNull(grid, $"Test blueprint {testMapName} not found.");
Assert.That(grid, Is.Not.Null, $"Test blueprint {testMapName} not found.");
float GetMapMoles()
{
@@ -96,13 +104,15 @@ namespace Content.IntegrationTests.Tests.Body
var coords = new Vector2(0.5f, -1f);
var coordinates = new EntityCoordinates(grid.Value, coords);
human = entityManager.SpawnEntity("HumanBodyDummy", coordinates);
respSys = EntitySystem.Get<RespiratorSystem>();
metaSys = EntitySystem.Get<MetabolizerSystem>();
respSys = entityManager.System<RespiratorSystem>();
metaSys = entityManager.System<MetabolizerSystem>();
relevantAtmos = entityManager.GetComponent<GridAtmosphereComponent>(grid.Value);
startingMoles = GetMapMoles();
Assert.True(entityManager.TryGetComponent(human, out body));
Assert.True(entityManager.HasComponent<RespiratorComponent>(human));
#pragma warning disable NUnit2045
Assert.That(entityManager.TryGetComponent(human, out body), Is.True);
Assert.That(entityManager.HasComponent<RespiratorComponent>(human), Is.True);
#pragma warning restore NUnit2045
});
// --- End setup
@@ -131,7 +141,10 @@ namespace Content.IntegrationTests.Tests.Body
public async Task NoSuffocationTest()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
{NoClient = true, ExtraPrototypes = Prototypes});
{
NoClient = true,
ExtraPrototypes = Prototypes
});
var server = pairTracker.Pair.Server;
var mapManager = server.ResolveDependency<IMapManager>();
@@ -149,10 +162,16 @@ namespace Content.IntegrationTests.Tests.Body
await server.WaitPost(() =>
{
mapId = mapManager.CreateMap();
grid = mapLoader.LoadGrid(mapId, testMapName);
Assert.That(mapLoader.TryLoad(mapId, testMapName, out var ents), Is.True);
var query = entityManager.GetEntityQuery<MapGridComponent>();
grid = ents
.Select<EntityUid, EntityUid?>(x => x)
.FirstOrDefault((uid) => uid.HasValue && query.HasComponent(uid.Value), null);
Assert.That(grid, Is.Not.Null);
});
Assert.NotNull(grid, $"Test blueprint {testMapName} not found.");
Assert.That(grid, Is.Not.Null, $"Test blueprint {testMapName} not found.");
await server.WaitAssertion(() =>
{
@@ -162,11 +181,12 @@ namespace Content.IntegrationTests.Tests.Body
human = entityManager.SpawnEntity("HumanBodyDummy", coordinates);
var mixture = entityManager.System<AtmosphereSystem>().GetContainingMixture(human);
#pragma warning disable NUnit2045
Assert.That(mixture.TotalMoles, Is.GreaterThan(0));
Assert.True(entityManager.HasComponent<BodyComponent>(human));
Assert.True(entityManager.TryGetComponent(human, out respirator));
Assert.False(respirator.SuffocationCycles > respirator.SuffocationCycleThreshold);
Assert.That(entityManager.HasComponent<BodyComponent>(human), Is.True);
Assert.That(entityManager.TryGetComponent(human, out respirator), Is.True);
Assert.That(respirator.SuffocationCycles, Is.LessThanOrEqualTo(respirator.SuffocationCycleThreshold));
#pragma warning restore NUnit2045
});
var increment = 10;
@@ -179,7 +199,7 @@ namespace Content.IntegrationTests.Tests.Body
await server.WaitRunTicks(increment);
await server.WaitAssertion(() =>
{
Assert.False(respirator.SuffocationCycles > respirator.SuffocationCycleThreshold,
Assert.That(respirator.SuffocationCycles, Is.LessThanOrEqualTo(respirator.SuffocationCycleThreshold),
$"Entity {entityManager.GetComponent<MetaDataComponent>(human).EntityName} is suffocating on tick {tick}");
});
}

View File

@@ -1,10 +1,8 @@
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Linq;
using Content.Shared.Body.Components;
using Content.Shared.Body.Systems;
using NUnit.Framework;
using Robust.Server.GameObjects;
using Robust.Server.Maps;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
@@ -85,10 +83,22 @@ public sealed class SaveLoadReparentTest
});
}
Assert.That(entities
.EntityQuery<BodyComponent>()
.Where(e => entities.GetComponent<MetaDataComponent>(e.Owner).EntityPrototype!.Name ==
"HumanBodyDummy"), Is.Not.Empty);
// Converts an entity query enumerator to an enumerable.
static IEnumerable<(EntityUid Uid, TComp Comp)> EnumerateQueryEnumerator<TComp>(EntityQueryEnumerator<TComp> query)
where TComp : Component
{
while (query.MoveNext(out var uid, out var comp))
yield return (uid, comp);
}
Assert.That(
EnumerateQueryEnumerator(
entities.EntityQueryEnumerator<BodyComponent>()
).Where((e) =>
entities.GetComponent<MetaDataComponent>(e.Uid).EntityPrototype!.Name == "HumanBodyDummy"
),
Is.Not.Empty
);
const string mapPath = $"/{nameof(SaveLoadReparentTest)}{nameof(Test)}map.yml";
@@ -96,22 +106,26 @@ public sealed class SaveLoadReparentTest
maps.DeleteMap(mapId);
mapId = maps.CreateMap();
mapLoader.LoadMap(mapId, mapPath);
Assert.That(mapLoader.TryLoad(mapId, mapPath, out _), Is.True);
var query = entities
.EntityQuery<BodyComponent>()
.Where(e => entities.GetComponent<MetaDataComponent>(e.Owner).EntityPrototype!.Name == "HumanBodyDummy")
.ToArray();
var query = EnumerateQueryEnumerator(
entities.EntityQueryEnumerator<BodyComponent>()
).Where((e) =>
entities.GetComponent<MetaDataComponent>(e.Uid).EntityPrototype!.Name == "HumanBodyDummy"
).ToArray();
Assert.That(query, Is.Not.Empty);
foreach (var body in query)
foreach (var (uid, body) in query)
{
human = body.Owner;
human = uid;
parts = bodySystem.GetBodyChildren(human).ToArray();
organs = bodySystem.GetBodyOrgans(human).ToArray();
Assert.That(parts, Is.Not.Empty);
Assert.That(organs, Is.Not.Empty);
Assert.Multiple(() =>
{
Assert.That(parts, Is.Not.Empty);
Assert.That(organs, Is.Not.Empty);
});
foreach (var (id, component) in parts)
{