Minor test fixes (#25174)

Stuff that probably shoulda been wrapped ig but our test runner stinky.
This commit is contained in:
metalgearsloth
2024-02-14 18:14:40 +11:00
committed by GitHub
parent 159eadebc8
commit 212c8b2b46
2 changed files with 69 additions and 45 deletions

View File

@@ -55,6 +55,8 @@ namespace Content.IntegrationTests.Tests.Construction
var valid = true; var valid = true;
var message = new StringBuilder(); var message = new StringBuilder();
await server.WaitPost(() =>
{
foreach (var graph in protoMan.EnumeratePrototypes<ConstructionGraphPrototype>()) foreach (var graph in protoMan.EnumeratePrototypes<ConstructionGraphPrototype>())
{ {
foreach (var node in graph.Nodes.Values) foreach (var node in graph.Nodes.Values)
@@ -79,9 +81,10 @@ namespace Content.IntegrationTests.Tests.Construction
} }
} }
} }
await pair.CleanReturnAsync(); });
Assert.That(valid, Is.True, $"One or more SpawnPrototype actions specified invalid entity prototypes!\n{message}"); Assert.That(valid, Is.True, $"One or more SpawnPrototype actions specified invalid entity prototypes!\n{message}");
await pair.CleanReturnAsync();
} }
[Test] [Test]
@@ -95,19 +98,24 @@ namespace Content.IntegrationTests.Tests.Construction
var valid = true; var valid = true;
var message = new StringBuilder(); var message = new StringBuilder();
await server.WaitPost(() =>
{
foreach (var graph in protoMan.EnumeratePrototypes<ConstructionGraphPrototype>()) foreach (var graph in protoMan.EnumeratePrototypes<ConstructionGraphPrototype>())
{ {
foreach (var node in graph.Nodes.Values) foreach (var node in graph.Nodes.Values)
{ {
foreach (var edge in node.Edges) foreach (var edge in node.Edges)
{ {
if (graph.Nodes.ContainsKey(edge.Target)) continue; if (graph.Nodes.ContainsKey(edge.Target))
continue;
valid = false; valid = false;
message.Append($"Invalid target \"{edge.Target}\" in edge on node \"{node.Name}\" of graph \"{graph.ID}\"\n"); message.Append(
$"Invalid target \"{edge.Target}\" in edge on node \"{node.Name}\" of graph \"{graph.ID}\"\n");
} }
} }
} }
});
Assert.That(valid, Is.True, $"One or more edges specified invalid node targets!\n{message}"); Assert.That(valid, Is.True, $"One or more edges specified invalid node targets!\n{message}");
await pair.CleanReturnAsync(); await pair.CleanReturnAsync();

View File

@@ -58,13 +58,17 @@ namespace Content.IntegrationTests.Tests.Construction
var protoMan = server.ResolveDependency<IPrototypeManager>(); var protoMan = server.ResolveDependency<IPrototypeManager>();
await server.WaitAssertion(() =>
{
foreach (var proto in protoMan.EnumeratePrototypes<ConstructionPrototype>()) foreach (var proto in protoMan.EnumeratePrototypes<ConstructionPrototype>())
{ {
var start = proto.StartNode; var start = proto.StartNode;
var graph = protoMan.Index<ConstructionGraphPrototype>(proto.Graph); var graph = protoMan.Index<ConstructionGraphPrototype>(proto.Graph);
Assert.That(graph.Nodes.ContainsKey(start), $"Found no startNode \"{start}\" on graph \"{graph.ID}\" for construction prototype \"{proto.ID}\"!"); Assert.That(graph.Nodes.ContainsKey(start),
$"Found no startNode \"{start}\" on graph \"{graph.ID}\" for construction prototype \"{proto.ID}\"!");
} }
});
await pair.CleanReturnAsync(); await pair.CleanReturnAsync();
} }
@@ -76,13 +80,17 @@ namespace Content.IntegrationTests.Tests.Construction
var protoMan = server.ResolveDependency<IPrototypeManager>(); var protoMan = server.ResolveDependency<IPrototypeManager>();
await server.WaitAssertion(() =>
{
foreach (var proto in protoMan.EnumeratePrototypes<ConstructionPrototype>()) foreach (var proto in protoMan.EnumeratePrototypes<ConstructionPrototype>())
{ {
var target = proto.TargetNode; var target = proto.TargetNode;
var graph = protoMan.Index<ConstructionGraphPrototype>(proto.Graph); var graph = protoMan.Index<ConstructionGraphPrototype>(proto.Graph);
Assert.That(graph.Nodes.ContainsKey(target), $"Found no targetNode \"{target}\" on graph \"{graph.ID}\" for construction prototype \"{proto.ID}\"!"); Assert.That(graph.Nodes.ContainsKey(target),
$"Found no targetNode \"{target}\" on graph \"{graph.ID}\" for construction prototype \"{proto.ID}\"!");
} }
});
await pair.CleanReturnAsync(); await pair.CleanReturnAsync();
} }
@@ -92,7 +100,6 @@ namespace Content.IntegrationTests.Tests.Construction
await using var pair = await PoolManager.GetServerClient(); await using var pair = await PoolManager.GetServerClient();
var server = pair.Server; var server = pair.Server;
var entMan = server.ResolveDependency<IEntityManager>();
var protoMan = server.ResolveDependency<IPrototypeManager>(); var protoMan = server.ResolveDependency<IPrototypeManager>();
var compFact = server.ResolveDependency<IComponentFactory>(); var compFact = server.ResolveDependency<IComponentFactory>();
@@ -126,6 +133,8 @@ namespace Content.IntegrationTests.Tests.Construction
var protoMan = server.ResolveDependency<IPrototypeManager>(); var protoMan = server.ResolveDependency<IPrototypeManager>();
var entMan = server.ResolveDependency<IEntityManager>(); var entMan = server.ResolveDependency<IEntityManager>();
await server.WaitAssertion(() =>
{
foreach (var proto in protoMan.EnumeratePrototypes<ConstructionPrototype>()) foreach (var proto in protoMan.EnumeratePrototypes<ConstructionPrototype>())
{ {
var start = proto.StartNode; var start = proto.StartNode;
@@ -133,15 +142,22 @@ namespace Content.IntegrationTests.Tests.Construction
var graph = protoMan.Index<ConstructionGraphPrototype>(proto.Graph); var graph = protoMan.Index<ConstructionGraphPrototype>(proto.Graph);
#pragma warning disable NUnit2045 // Interdependent assertions. #pragma warning disable NUnit2045 // Interdependent assertions.
Assert.That(graph.TryPath(start, target, out var path), $"Unable to find path from \"{start}\" to \"{target}\" on graph \"{graph.ID}\""); Assert.That(graph.TryPath(start, target, out var path),
Assert.That(path, Has.Length.GreaterThanOrEqualTo(1), $"Unable to find path from \"{start}\" to \"{target}\" on graph \"{graph.ID}\"."); $"Unable to find path from \"{start}\" to \"{target}\" on graph \"{graph.ID}\"");
Assert.That(path, Has.Length.GreaterThanOrEqualTo(1),
$"Unable to find path from \"{start}\" to \"{target}\" on graph \"{graph.ID}\".");
var next = path[0]; var next = path[0];
var nextId = next.Entity.GetId(null, null, new(entMan)); var nextId = next.Entity.GetId(null, null, new(entMan));
Assert.That(nextId, Is.Not.Null, $"The next node ({next.Name}) in the path from the start node ({start}) to the target node ({target}) must specify an entity! Graph: {graph.ID}"); Assert.That(nextId, Is.Not.Null,
Assert.That(protoMan.TryIndex(nextId, out EntityPrototype entity), $"The next node ({next.Name}) in the path from the start node ({start}) to the target node ({target}) specified an invalid entity prototype ({nextId} [{next.Entity}])"); $"The next node ({next.Name}) in the path from the start node ({start}) to the target node ({target}) must specify an entity! Graph: {graph.ID}");
Assert.That(entity.Components.ContainsKey("Construction"), $"The next node ({next.Name}) in the path from the start node ({start}) to the target node ({target}) specified an entity prototype ({next.Entity}) without a ConstructionComponent."); Assert.That(protoMan.TryIndex(nextId, out EntityPrototype entity),
$"The next node ({next.Name}) in the path from the start node ({start}) to the target node ({target}) specified an invalid entity prototype ({nextId} [{next.Entity}])");
Assert.That(entity.Components.ContainsKey("Construction"),
$"The next node ({next.Name}) in the path from the start node ({start}) to the target node ({target}) specified an entity prototype ({next.Entity}) without a ConstructionComponent.");
#pragma warning restore NUnit2045 #pragma warning restore NUnit2045
} }
});
await pair.CleanReturnAsync(); await pair.CleanReturnAsync();
} }
} }