]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix tests (#27711)
authorDrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com>
Mon, 6 May 2024 02:08:56 +0000 (19:08 -0700)
committerGitHub <noreply@github.com>
Mon, 6 May 2024 02:08:56 +0000 (19:08 -0700)
* Fix tests

* Fix test fail

* Apply same fix to other tests

Content.IntegrationTests/Tests/Interaction/InteractionTest.EntitySpecifier.cs
Content.IntegrationTests/Tests/Interaction/InteractionTest.EntitySpecifierCollection.cs
Content.IntegrationTests/Tests/Interaction/InteractionTest.Helpers.cs
Content.IntegrationTests/Tests/StorageTest.cs

index 414cf4bb56f21c9c4dc12ebd295cdcd695395ce2..37dca721373b97248474c6c819959546c26b37e6 100644 (file)
@@ -3,6 +3,7 @@ using Content.Shared.Stacks;
 using Robust.Shared.GameObjects;
 using Robust.Shared.Map;
 using Robust.Shared.Prototypes;
+using static Robust.UnitTesting.RobustIntegrationTest;
 
 namespace Content.IntegrationTests.Tests.Interaction;
 
@@ -54,7 +55,7 @@ public abstract partial class InteractionTest
         /// <summary>
         /// Convert applicable entity prototypes into stack prototypes.
         /// </summary>
-        public void ConvertToStack(IPrototypeManager protoMan, IComponentFactory factory)
+        public async Task ConvertToStack(IPrototypeManager protoMan, IComponentFactory factory, ServerIntegrationInstance server)
         {
             if (Converted)
                 return;
@@ -73,11 +74,14 @@ public abstract partial class InteractionTest
                 return;
             }
 
-            if (entProto.TryGetComponent<StackComponent>(factory.GetComponentName(typeof(StackComponent)),
-                    out var stackComp))
+            StackComponent? stack = null;
+            await server.WaitPost(() =>
             {
-                Prototype = stackComp.StackTypeId;
-            }
+                entProto.TryGetComponent(factory.GetComponentName(typeof(StackComponent)), out stack);
+            });
+
+            if (stack != null)
+                Prototype = stack.StackTypeId;
         }
     }
 
@@ -100,11 +104,14 @@ public abstract partial class InteractionTest
             return default;
         }
 
-        if (entProto.TryGetComponent<StackComponent>(Factory.GetComponentName(typeof(StackComponent)),
-                out var stackComp))
+        StackComponent? stack = null;
+        await Server.WaitPost(() =>
         {
-            return await SpawnEntity((stackComp.StackTypeId, spec.Quantity), coords);
-        }
+            entProto.TryGetComponent(Factory.GetComponentName(typeof(StackComponent)), out stack);
+        });
+
+        if (stack != null)
+            return await SpawnEntity((stack.StackTypeId, spec.Quantity), coords);
 
         Assert.That(spec.Quantity, Is.EqualTo(1), "SpawnEntity only supports returning a singular entity");
         await Server.WaitPost(() => uid = SEntMan.SpawnEntity(spec.Prototype, coords));
index 520d2699c14a3778f7a8053a228781f20913b0c4..7f7de3318b4aef281cfc4746d86fbc42067e8738 100644 (file)
@@ -5,6 +5,7 @@ using Content.Shared.Stacks;
 using Robust.Shared.GameObjects;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Utility;
+using static Robust.UnitTesting.RobustIntegrationTest;
 
 namespace Content.IntegrationTests.Tests.Interaction;
 
@@ -111,7 +112,7 @@ public abstract partial class InteractionTest
         /// <summary>
         /// Convert applicable entity prototypes into stack prototypes.
         /// </summary>
-        public void ConvertToStacks(IPrototypeManager protoMan, IComponentFactory factory)
+        public async Task ConvertToStacks(IPrototypeManager protoMan, IComponentFactory factory, ServerIntegrationInstance server)
         {
             if (Converted)
                 return;
@@ -130,14 +131,17 @@ public abstract partial class InteractionTest
                     continue;
                 }
 
-                if (!entProto.TryGetComponent<StackComponent>(factory.GetComponentName(typeof(StackComponent)),
-                        out var stackComp))
+                StackComponent? stack = null;
+                await server.WaitPost(() =>
                 {
+                    entProto.TryGetComponent(factory.GetComponentName(typeof(StackComponent)), out stack);
+                });
+
+                if (stack == null)
                     continue;
-                }
 
                 toRemove.Add(id);
-                toAdd.Add((stackComp.StackTypeId, quantity));
+                toAdd.Add((stack.StackTypeId, quantity));
             }
 
             foreach (var id in toRemove)
index 95cf8a06dfa5613bf20c5347a0f550e7e02a6c43..19ca83a9715d5e44d95a682156a9035846de3de7 100644 (file)
@@ -5,12 +5,9 @@ using System.Linq;
 using System.Numerics;
 using System.Reflection;
 using Content.Client.Construction;
-using Content.Server.Atmos;
-using Content.Server.Atmos.Components;
 using Content.Server.Atmos.EntitySystems;
 using Content.Server.Construction.Components;
 using Content.Server.Gravity;
-using Content.Server.Item;
 using Content.Server.Power.Components;
 using Content.Shared.Atmos;
 using Content.Shared.Construction.Prototypes;
@@ -634,7 +631,7 @@ public abstract partial class InteractionTest
         var entities = await DoEntityLookup(flags);
         var found = ToEntityCollection(entities);
         expected.Remove(found);
-        expected.ConvertToStacks(ProtoMan, Factory);
+        await expected.ConvertToStacks(ProtoMan, Factory, Server);
 
         if (expected.Entities.Count == 0)
             return;
@@ -670,7 +667,7 @@ public abstract partial class InteractionTest
         LookupFlags flags = LookupFlags.Uncontained | LookupFlags.Contained,
         bool shouldSucceed = true)
     {
-        spec.ConvertToStack(ProtoMan, Factory);
+        await spec.ConvertToStack(ProtoMan, Factory, Server);
 
         var entities = await DoEntityLookup(flags);
         foreach (var uid in entities)
index 659b310661b0b2a5d064be082ea9393ff0622f4a..2d28534347d248130ec597db03bc7055723ded2d 100644 (file)
@@ -92,23 +92,32 @@ namespace Content.IntegrationTests.Tests
             var allSizes = protoMan.EnumeratePrototypes<ItemSizePrototype>().ToList();
             allSizes.Sort();
 
-            Assert.Multiple(() =>
+            await Assert.MultipleAsync(async () =>
             {
                 foreach (var proto in pair.GetPrototypesWithComponent<StorageFillComponent>())
                 {
                     if (proto.HasComponent<EntityStorageComponent>(compFact))
                         continue;
 
-                    if (!proto.TryGetComponent<StorageComponent>("Storage", out var storage))
+                    StorageComponent? storage = null;
+                    ItemComponent? item = null;
+                    StorageFillComponent fill = default!;
+                    var size = 0;
+                    await server.WaitAssertion(() =>
                     {
-                        Assert.Fail($"Entity {proto.ID} has storage-fill without a storage component!");
-                        continue;
-                    }
+                        if (!proto.TryGetComponent("Storage", out storage))
+                        {
+                            Assert.Fail($"Entity {proto.ID} has storage-fill without a storage component!");
+                            return;
+                        }
 
-                    proto.TryGetComponent<ItemComponent>("Item", out var item);
+                        proto.TryGetComponent("Item", out item);
+                        fill = (StorageFillComponent) proto.Components[id].Component;
+                        size = GetFillSize(fill, false, protoMan, itemSys);
+                    });
 
-                    var fill = (StorageFillComponent) proto.Components[id].Component;
-                    var size = GetFillSize(fill, false, protoMan, itemSys);
+                    if (storage == null)
+                        continue;
 
                     var maxSize = storage.MaxItemSize;
                     if (storage.MaxItemSize == null)
@@ -138,7 +147,13 @@ namespace Content.IntegrationTests.Tests
                         if (!protoMan.TryIndex<EntityPrototype>(entry.PrototypeId, out var fillItem))
                             continue;
 
-                        if (!fillItem.TryGetComponent<ItemComponent>("Item", out var entryItem))
+                        ItemComponent? entryItem = null;
+                        await server.WaitPost(() =>
+                        {
+                            fillItem.TryGetComponent("Item", out entryItem);
+                        });
+
+                        if (entryItem == null)
                             continue;
 
                         Assert.That(protoMan.Index(entryItem.Size).Weight,
@@ -164,25 +179,25 @@ namespace Content.IntegrationTests.Tests
 
             var itemSys = entMan.System<SharedItemSystem>();
 
-            Assert.Multiple(() =>
+            foreach (var proto in pair.GetPrototypesWithComponent<StorageFillComponent>())
             {
-                foreach (var proto in pair.GetPrototypesWithComponent<StorageFillComponent>())
-                {
-                    if (proto.HasComponent<StorageComponent>(compFact))
-                        continue;
+                if (proto.HasComponent<StorageComponent>(compFact))
+                    continue;
 
-                    if (!proto.TryGetComponent<EntityStorageComponent>("EntityStorage", out var entStorage))
-                    {
+                await server.WaitAssertion(() =>
+                {
+                    if (!proto.TryGetComponent("EntityStorage", out EntityStorageComponent? entStorage))
                         Assert.Fail($"Entity {proto.ID} has storage-fill without a storage component!");
-                        continue;
-                    }
+
+                    if (entStorage == null)
+                        return;
 
                     var fill = (StorageFillComponent) proto.Components[id].Component;
                     var size = GetFillSize(fill, true, protoMan, itemSys);
                     Assert.That(size, Is.LessThanOrEqualTo(entStorage.Capacity),
                         $"{proto.ID} storage fill is too large.");
-                }
-            });
+                });
+            }
             await pair.CleanReturnAsync();
         }