]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Minor test fixes (#25174)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Wed, 14 Feb 2024 07:14:40 +0000 (18:14 +1100)
committerGitHub <noreply@github.com>
Wed, 14 Feb 2024 07:14:40 +0000 (18:14 +1100)
Stuff that probably shoulda been wrapped ig but our test runner stinky.

Content.IntegrationTests/Tests/Construction/ConstructionActionValid.cs
Content.IntegrationTests/Tests/Construction/ConstructionPrototypeTest.cs

index 408b0e0bd035b45241721ec9348936b3dfa2928b..c59b42d63892eb0bd048637e2e2db96e49d2a630 100644 (file)
@@ -55,33 +55,36 @@ namespace Content.IntegrationTests.Tests.Construction
             var valid = true;
             var message = new StringBuilder();
 
-            foreach (var graph in protoMan.EnumeratePrototypes<ConstructionGraphPrototype>())
+            await server.WaitPost(() =>
             {
-                foreach (var node in graph.Nodes.Values)
+                foreach (var graph in protoMan.EnumeratePrototypes<ConstructionGraphPrototype>())
                 {
-                    foreach (var action in node.Actions)
+                    foreach (var node in graph.Nodes.Values)
                     {
-                        if (IsValid(action, protoMan, out var prototype)) continue;
-
-                        valid = false;
-                        message.Append($"Invalid entity prototype \"{prototype}\" on graph action in node \"{node.Name}\" of graph \"{graph.ID}\"\n");
-                    }
-
-                    foreach (var edge in node.Edges)
-                    {
-                        foreach (var action in edge.Completed)
+                        foreach (var action in node.Actions)
                         {
                             if (IsValid(action, protoMan, out var prototype)) continue;
 
                             valid = false;
-                            message.Append($"Invalid entity prototype \"{prototype}\" on graph action in edge \"{edge.Target}\" of node \"{node.Name}\" of graph \"{graph.ID}\"\n");
+                            message.Append($"Invalid entity prototype \"{prototype}\" on graph action in node \"{node.Name}\" of graph \"{graph.ID}\"\n");
+                        }
+
+                        foreach (var edge in node.Edges)
+                        {
+                            foreach (var action in edge.Completed)
+                            {
+                                if (IsValid(action, protoMan, out var prototype)) continue;
+
+                                valid = false;
+                                message.Append($"Invalid entity prototype \"{prototype}\" on graph action in edge \"{edge.Target}\" of node \"{node.Name}\" of graph \"{graph.ID}\"\n");
+                            }
                         }
                     }
                 }
-            }
-            await pair.CleanReturnAsync();
+            });
 
             Assert.That(valid, Is.True, $"One or more SpawnPrototype actions specified invalid entity prototypes!\n{message}");
+            await pair.CleanReturnAsync();
         }
 
         [Test]
@@ -95,19 +98,24 @@ namespace Content.IntegrationTests.Tests.Construction
             var valid = true;
             var message = new StringBuilder();
 
-            foreach (var graph in protoMan.EnumeratePrototypes<ConstructionGraphPrototype>())
+            await server.WaitPost(() =>
             {
-                foreach (var node in graph.Nodes.Values)
+                foreach (var graph in protoMan.EnumeratePrototypes<ConstructionGraphPrototype>())
                 {
-                    foreach (var edge in node.Edges)
+                    foreach (var node in graph.Nodes.Values)
                     {
-                        if (graph.Nodes.ContainsKey(edge.Target)) continue;
+                        foreach (var edge in node.Edges)
+                        {
+                            if (graph.Nodes.ContainsKey(edge.Target))
+                                continue;
 
-                        valid = false;
-                        message.Append($"Invalid target \"{edge.Target}\" in edge on node \"{node.Name}\" of graph \"{graph.ID}\"\n");
+                            valid = false;
+                            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}");
             await pair.CleanReturnAsync();
index 01173c9660f25d7f67e60feb786d368beb5e6172..d3a10dcfaf4432bb49b5fb425c3db1510c5992fd 100644 (file)
@@ -58,13 +58,17 @@ namespace Content.IntegrationTests.Tests.Construction
 
             var protoMan = server.ResolveDependency<IPrototypeManager>();
 
-            foreach (var proto in protoMan.EnumeratePrototypes<ConstructionPrototype>())
+            await server.WaitAssertion(() =>
             {
-                var start = proto.StartNode;
-                var graph = protoMan.Index<ConstructionGraphPrototype>(proto.Graph);
+                foreach (var proto in protoMan.EnumeratePrototypes<ConstructionPrototype>())
+                {
+                    var start = proto.StartNode;
+                    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();
         }
 
@@ -76,13 +80,17 @@ namespace Content.IntegrationTests.Tests.Construction
 
             var protoMan = server.ResolveDependency<IPrototypeManager>();
 
-            foreach (var proto in protoMan.EnumeratePrototypes<ConstructionPrototype>())
+            await server.WaitAssertion(() =>
             {
-                var target = proto.TargetNode;
-                var graph = protoMan.Index<ConstructionGraphPrototype>(proto.Graph);
+                foreach (var proto in protoMan.EnumeratePrototypes<ConstructionPrototype>())
+                {
+                    var target = proto.TargetNode;
+                    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();
         }
 
@@ -92,7 +100,6 @@ namespace Content.IntegrationTests.Tests.Construction
             await using var pair = await PoolManager.GetServerClient();
             var server = pair.Server;
 
-            var entMan = server.ResolveDependency<IEntityManager>();
             var protoMan = server.ResolveDependency<IPrototypeManager>();
             var compFact = server.ResolveDependency<IComponentFactory>();
 
@@ -126,22 +133,31 @@ namespace Content.IntegrationTests.Tests.Construction
             var protoMan = server.ResolveDependency<IPrototypeManager>();
             var entMan = server.ResolveDependency<IEntityManager>();
 
-            foreach (var proto in protoMan.EnumeratePrototypes<ConstructionPrototype>())
+            await server.WaitAssertion(() =>
             {
-                var start = proto.StartNode;
-                var target = proto.TargetNode;
-                var graph = protoMan.Index<ConstructionGraphPrototype>(proto.Graph);
+                foreach (var proto in protoMan.EnumeratePrototypes<ConstructionPrototype>())
+                {
+                    var start = proto.StartNode;
+                    var target = proto.TargetNode;
+                    var graph = protoMan.Index<ConstructionGraphPrototype>(proto.Graph);
 
 #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(path, Has.Length.GreaterThanOrEqualTo(1), $"Unable to find path from \"{start}\" to \"{target}\" on graph \"{graph.ID}\".");
-                var next = path[0];
-                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(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.");
+                    Assert.That(graph.TryPath(start, target, out var path),
+                        $"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 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(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
-            }
+                }
+            });
+
             await pair.CleanReturnAsync();
         }
     }