From d58786faf46d4ed57d76aff3acca1e40e19543cf Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Sat, 5 Aug 2023 16:16:48 +1200 Subject: [PATCH] Remove PoolSettings.ExtraPrototypes option (#18678) --- .../DeviceNetworkingBenchmark.cs | 18 +- Content.Benchmarks/Program.cs | 3 + .../PoolManager.Prototypes.cs | 38 ++++ Content.IntegrationTests/PoolManager.cs | 189 ++++++++++-------- .../PoolManagerTestEventHandler.cs | 2 + .../TestPrototypesAttribute.cs | 9 + .../Tests/Atmos/AlarmThresholdTest.cs | 7 +- .../Tests/Body/LegTest.cs | 4 +- .../Tests/Body/LungTest.cs | 15 +- .../Tests/Body/SaveLoadReparentTest.cs | 4 +- .../Tests/Buckle/BuckleTest.cs | 11 +- Content.IntegrationTests/Tests/CargoTest.cs | 14 +- .../Tests/Chemistry/SolutionSystemTests.cs | 15 +- .../Tests/Chemistry/TryAllReactionsTest.cs | 5 +- .../Tests/Commands/RejuvenateTest.cs | 4 +- .../Construction/ConstructionPrototypeTest.cs | 2 +- .../Tests/ContainerOcclusionTest.cs | 7 +- .../Tests/Damageable/DamageableTest.cs | 6 +- .../DestructibleDamageGroupTest.cs | 3 +- .../DestructibleDamageTypeTest.cs | 3 +- .../DestructibleDestructionTest.cs | 3 +- .../DestructibleTestPrototypes.cs | 3 +- .../DestructibleThresholdActivationTest.cs | 3 +- .../Tests/DeviceNetwork/DeviceNetworkTest.cs | 18 +- .../Tests/Disposal/DisposalUnitTest.cs | 10 +- .../Tests/DoAfter/DoAfterServerTest.cs | 15 +- .../Tests/Doors/AirlockTest.cs | 27 ++- .../Tests/DummyIconTest.cs | 2 +- Content.IntegrationTests/Tests/EntityTest.cs | 3 + .../Components/ActionBlocking/HandCuffTest.cs | 12 +- .../Tests/Gravity/WeightlessStatusTests.cs | 16 +- .../Tests/GravityGridTest.cs | 10 +- .../Tests/HumanInventoryUniformSlotsTest.cs | 9 +- .../Click/InteractionSystemTests.cs | 7 +- .../Tests/Interaction/InteractionTest.cs | 7 +- .../Tests/InventoryHelpersTest.cs | 3 +- .../Tests/MachineBoardTest.cs | 10 +- .../Tests/MaterialArbitrageTest.cs | 6 +- .../Tests/Minds/GhostRoleTests.cs | 3 +- .../Tests/Minds/MindTests.cs | 3 +- .../Tests/PostMapInitTest.cs | 187 ++++++++--------- .../Tests/Power/PowerTest.cs | 44 ++-- .../Tests/PrototypeSaveTest.cs | 3 + .../Tests/ResearchTest.cs | 3 + .../Tests/Station/StationJobsTest.cs | 22 +- Content.IntegrationTests/Tests/Tag/TagTest.cs | 12 +- .../Utility/EntitySystemExtensionsTest.cs | 6 +- .../Tests/Utility/EntityWhitelistTest.cs | 33 +-- .../Tests/VendingMachineRestockTest.cs | 19 +- Content.MapRenderer/Program.cs | 2 + Content.YAMLLinter/Program.cs | 2 + 51 files changed, 463 insertions(+), 399 deletions(-) create mode 100644 Content.IntegrationTests/PoolManager.Prototypes.cs create mode 100644 Content.IntegrationTests/TestPrototypesAttribute.cs diff --git a/Content.Benchmarks/DeviceNetworkingBenchmark.cs b/Content.Benchmarks/DeviceNetworkingBenchmark.cs index 7694c0f37f..30426dddb1 100644 --- a/Content.Benchmarks/DeviceNetworkingBenchmark.cs +++ b/Content.Benchmarks/DeviceNetworkingBenchmark.cs @@ -26,10 +26,12 @@ public class DeviceNetworkingBenchmark private NetworkPayload _payload = default!; + + [TestPrototypes] private const string Prototypes = @" - type: entity - name: DummyNetworkDevice - id: DummyNetworkDevice + name: DummyNetworkDevicePrivate + id: DummyNetworkDevicePrivate components: - type: DeviceNetwork transmitFrequency: 100 @@ -56,7 +58,7 @@ public class DeviceNetworkingBenchmark public async Task SetupAsync() { ProgramShared.PathOffset = "../../../../"; - _pair = await PoolManager.GetServerClient(new PoolSettings { NoClient = true, ExtraPrototypes = Prototypes }); + _pair = await PoolManager.GetServerClient(new PoolSettings { NoClient = true }); var server = _pair.Pair.Server; await server.WaitPost(() => @@ -73,17 +75,23 @@ public class DeviceNetworkingBenchmark ["testbool"] = true }; - _sourceEntity = entityManager.SpawnEntity("DummyNetworkDevice", MapCoordinates.Nullspace); + _sourceEntity = entityManager.SpawnEntity("DummyNetworkDevicePrivate", MapCoordinates.Nullspace); _sourceWirelessEntity = entityManager.SpawnEntity("DummyWirelessNetworkDevice", MapCoordinates.Nullspace); for (var i = 0; i < EntityCount; i++) { - _targetEntities.Add(entityManager.SpawnEntity("DummyNetworkDevice", MapCoordinates.Nullspace)); + _targetEntities.Add(entityManager.SpawnEntity("DummyNetworkDevicePrivate", MapCoordinates.Nullspace)); _targetWirelessEntities.Add(entityManager.SpawnEntity("DummyWirelessNetworkDevice", MapCoordinates.Nullspace)); } }); } + [GlobalCleanup] + public async Task Cleanup() + { + await _pair.DisposeAsync(); + } + [Benchmark(Baseline = true, Description = "Entity Events")] public async Task EventSentBaseline() { diff --git a/Content.Benchmarks/Program.cs b/Content.Benchmarks/Program.cs index ae2d7817b9..f5876307a5 100644 --- a/Content.Benchmarks/Program.cs +++ b/Content.Benchmarks/Program.cs @@ -20,6 +20,7 @@ namespace Content.Benchmarks public static async Task MainAsync(string[] args) { + PoolManager.Startup(typeof(Program).Assembly); var pair = await PoolManager.GetServerClient(); var gameMaps = pair.Pair.Server.ResolveDependency().EnumeratePrototypes().ToList(); MapLoadBenchmark.MapsSource = gameMaps.Select(x => x.ID); @@ -33,6 +34,8 @@ namespace Content.Benchmarks var config = Environment.GetEnvironmentVariable("ROBUST_BENCHMARKS_ENABLE_SQL") != null ? DefaultSQLConfig.Instance : null; BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config); #endif + + PoolManager.Shutdown(); } } } diff --git a/Content.IntegrationTests/PoolManager.Prototypes.cs b/Content.IntegrationTests/PoolManager.Prototypes.cs new file mode 100644 index 0000000000..760e8b1d37 --- /dev/null +++ b/Content.IntegrationTests/PoolManager.Prototypes.cs @@ -0,0 +1,38 @@ +#nullable enable +using System.Collections.Generic; +using System.Reflection; +using Robust.Shared.Utility; + +namespace Content.IntegrationTests; + +// Partial class for handling the discovering and storing test prototypes. +public static partial class PoolManager +{ + private static List _testPrototypes = new(); + + private const BindingFlags Flags = BindingFlags.Static + | BindingFlags.NonPublic + | BindingFlags.Public + | BindingFlags.DeclaredOnly; + + private static void DiscoverTestPrototypes(Assembly? assembly = null) + { + assembly ??= typeof(PoolManager).Assembly; + _testPrototypes.Clear(); + + foreach (var type in assembly.GetTypes()) + { + foreach (var field in type.GetFields(Flags)) + { + if (!field.HasCustomAttribute()) + continue; + + var val = field.GetValue(null); + if (val is not string str) + throw new Exception($"TestPrototypeAttribute is only valid on non-null string fields"); + + _testPrototypes.Add(str); + } + } + } +} diff --git a/Content.IntegrationTests/PoolManager.cs b/Content.IntegrationTests/PoolManager.cs index 27e03fe32c..7076212c16 100644 --- a/Content.IntegrationTests/PoolManager.cs +++ b/Content.IntegrationTests/PoolManager.cs @@ -1,6 +1,8 @@ +#nullable enable using System.Collections.Generic; using System.IO; using System.Linq; +using System.Reflection; using System.Text; using System.Threading; using Content.Client.IoC; @@ -27,6 +29,7 @@ using Robust.Shared.Map.Components; using Robust.Shared.Network; using Robust.Shared.Prototypes; using Robust.Shared.Timing; +using Robust.Shared.Utility; using Robust.UnitTesting; [assembly: LevelOfParallelism(3)] @@ -36,7 +39,7 @@ namespace Content.IntegrationTests; /// /// Making clients, and servers is slow, this manages a pool of them so tests can reuse them. /// -public static class PoolManager +public static partial class PoolManager { public const string TestMap = "Empty"; @@ -62,23 +65,12 @@ public static class PoolManager private static int _pairId; private static readonly object PairLock = new(); + private static bool _initialized; // Pair, IsBorrowed private static readonly Dictionary Pairs = new(); private static bool _dead; - private static Exception _poolFailureReason; - - private static async Task ConfigurePrototypes(RobustIntegrationTest.IntegrationInstance instance, - PoolSettings settings) - { - await instance.WaitPost(() => - { - var prototypeManager = IoCManager.Resolve(); - var changes = new Dictionary>(); - prototypeManager.LoadString(settings.ExtraPrototypes.Trim(), true, changes); - prototypeManager.ReloadPrototypes(changes); - }); - } + private static Exception? _poolFailureReason; private static async Task<(RobustIntegrationTest.ServerIntegrationInstance, PoolTestLogHandler)> GenerateServer( PoolSettings poolSettings, @@ -86,7 +78,6 @@ public static class PoolManager { var options = new RobustIntegrationTest.ServerIntegrationOptions { - ExtraPrototypes = poolSettings.ExtraPrototypes, ContentStart = true, Options = new ServerOptions() { @@ -144,6 +135,8 @@ public static class PoolManager { pair.Kill(); } + + _initialized = false; } public static string DeathReport() @@ -174,7 +167,6 @@ public static class PoolManager { FailureLogLevel = LogLevel.Warning, ContentStart = true, - ExtraPrototypes = poolSettings.ExtraPrototypes, ContentAssemblies = new[] { typeof(Shared.Entry.EntryPoint).Assembly, @@ -257,7 +249,7 @@ public static class PoolManager /// /// See /// - public static async Task GetServerClient(PoolSettings poolSettings = null) + public static async Task GetServerClient(PoolSettings? poolSettings = null) { return await GetServerClientPair(poolSettings ?? new PoolSettings()); } @@ -269,6 +261,9 @@ public static class PoolManager private static async Task GetServerClientPair(PoolSettings poolSettings) { + if (!_initialized) + throw new InvalidOperationException($"Pool manager has not been initialized"); + // Trust issues with the AsyncLocal that backs this. var testContext = TestContext.CurrentContext; var testOut = TestContext.Out; @@ -277,7 +272,7 @@ public static class PoolManager var currentTestName = poolSettings.TestName ?? GetDefaultTestName(testContext); var poolRetrieveTimeWatch = new Stopwatch(); await testOut.WriteLineAsync($"{nameof(GetServerClientPair)}: Called by test {currentTestName}"); - Pair pair = null; + Pair? pair = null; try { poolRetrieveTimeWatch.Start(); @@ -386,11 +381,11 @@ public static class PoolManager Assert.That(status, Is.EqualTo(expected)); } - private static Pair GrabOptimalPair(PoolSettings poolSettings) + private static Pair? GrabOptimalPair(PoolSettings poolSettings) { lock (PairLock) { - Pair fallback = null; + Pair? fallback = null; foreach (var pair in Pairs.Keys) { if (Pairs[pair]) @@ -457,7 +452,7 @@ public static class PoolManager cNetMgr.ClientConnect(null!, 0, null!); }); } - await ReallyBeIdle(pair, 11); + await ReallyBeIdle(pair, 5); await testOut.WriteLineAsync($"Recycling: {methodWatch.Elapsed.TotalMilliseconds} ms: Disconnecting client, and restarting server"); @@ -466,43 +461,7 @@ public static class PoolManager cNetMgr.ClientDisconnect("Test pooling cleanup disconnect"); }); - await ReallyBeIdle(pair, 10); - - if (!string.IsNullOrWhiteSpace(pair.Settings.ExtraPrototypes)) - { - await testOut.WriteLineAsync($"Recycling: {methodWatch.Elapsed.TotalMilliseconds} ms: Removing prototypes"); - if (!pair.Settings.NoServer) - { - var serverProtoManager = pair.Server.ResolveDependency(); - await pair.Server.WaitPost(() => - { - serverProtoManager.RemoveString(pair.Settings.ExtraPrototypes.Trim()); - }); - } - if (!pair.Settings.NoClient) - { - var clientProtoManager = pair.Client.ResolveDependency(); - await pair.Client.WaitPost(() => - { - clientProtoManager.RemoveString(pair.Settings.ExtraPrototypes.Trim()); - }); - } - - await ReallyBeIdle(pair, 1); - } - - if (poolSettings.ExtraPrototypes != null) - { - await testOut.WriteLineAsync($"Recycling: {methodWatch.Elapsed.TotalMilliseconds} ms: Adding prototypes"); - if (!poolSettings.NoServer) - { - await ConfigurePrototypes(pair.Server, poolSettings); - } - if (!poolSettings.NoClient) - { - await ConfigurePrototypes(pair.Client, poolSettings); - } - } + await ReallyBeIdle(pair, 5); configManager.SetCVar(CCVars.GameMap, poolSettings.Map); await testOut.WriteLineAsync($"Recycling: {methodWatch.Elapsed.TotalMilliseconds} ms: Restarting server again"); @@ -548,6 +507,7 @@ we are just going to end this here to save a lot of time. This is the exception Assert.Fail("The pool was shut down"); } } + private static async Task CreateServerClientPair(PoolSettings poolSettings, TextWriter testOut) { Pair pair; @@ -563,6 +523,9 @@ we are just going to end this here to save a lot of time. This is the exception ClientLogHandler = clientLog, PairId = Interlocked.Increment(ref _pairId) }; + + if (!poolSettings.NoLoadTestPrototypes) + await pair.LoadPrototypes(_testPrototypes!); } catch (Exception ex) { @@ -757,6 +720,19 @@ we are just going to end this here to save a lot of time. This is the exception return list; } + + /// + /// Initialize the pool manager. + /// + /// Assembly to search for to discover extra test prototypes. + public static void Startup(Assembly? assembly) + { + if (_initialized) + throw new InvalidOperationException("Already initialized"); + + _initialized = true; + DiscoverTestPrototypes(assembly); + } } /// @@ -766,17 +742,15 @@ we are just going to end this here to save a lot of time. This is the exception /// public sealed class PoolSettings { - // TODO: We can make more of these pool-able, if we need enough of them for it to matter - /// /// If the returned pair must not be reused /// - public bool MustNotBeReused => Destructive || NoLoadContent || NoToolsExtraPrototypes; + public bool MustNotBeReused => Destructive || NoLoadContent || NoLoadTestPrototypes; /// /// If the given pair must be brand new /// - public bool MustBeNew => Fresh || NoLoadContent || NoToolsExtraPrototypes; + public bool MustBeNew => Fresh || NoLoadContent || NoLoadTestPrototypes; /// /// If the given pair must not be connected @@ -816,9 +790,11 @@ public sealed class PoolSettings public bool NoLoadContent { get; init; } /// - /// Set this to raw yaml text to load prototypes onto the given server/client pair. + /// This will return a server-client pair that has not loaded test prototypes. + /// Try avoiding this whenever possible, as this will always create & destroy a new pair. + /// Use if you need to exclude test prototypees. /// - public string ExtraPrototypes { get; init; } + public bool NoLoadTestPrototypes { get; init; } /// /// Set this to true to disable the NetInterp CVar on the given server/client pair @@ -848,7 +824,7 @@ public sealed class PoolSettings /// /// Overrides the test name detection, and uses this in the test history instead /// - public string TestName { get; set; } + public string? TestName { get; set; } /// /// Tries to guess if we can skip recycling the server/client pair. @@ -870,19 +846,8 @@ public sealed class PoolSettings return NotConnected == nextSettings.NotConnected && DummyTicker == nextSettings.DummyTicker && Map == nextSettings.Map - && InLobby == nextSettings.InLobby - && ExtraPrototypes == nextSettings.ExtraPrototypes; + && InLobby == nextSettings.InLobby; } - - // Prototype hot reload is not available outside TOOLS builds, - // so we can't pool test instances that use ExtraPrototypes without TOOLS. -#if TOOLS -#pragma warning disable CA1822 // Can't be marked as static b/c the other branch exists but Omnisharp can't see both. - private bool NoToolsExtraPrototypes => false; -#pragma warning restore CA1822 -#else - private bool NoToolsExtraPrototypes => !string.IsNullOrEmpty(ExtraPrototypes); -#endif } /// @@ -893,7 +858,7 @@ public sealed class TestMapData public EntityUid MapUid { get; set; } public EntityUid GridUid { get; set; } public MapId MapId { get; set; } - public MapGridComponent MapGrid { get; set; } + public MapGridComponent MapGrid { get; set; } = default!; public EntityCoordinates GridCoords { get; set; } public MapCoordinates MapCoords { get; set; } public TileRef Tile { get; set; } @@ -907,12 +872,15 @@ public sealed class Pair public bool Dead { get; private set; } public int PairId { get; init; } public List TestHistory { get; set; } = new(); - public PoolSettings Settings { get; set; } - public RobustIntegrationTest.ServerIntegrationInstance Server { get; init; } - public RobustIntegrationTest.ClientIntegrationInstance Client { get; init; } + public PoolSettings Settings { get; set; } = default!; + public RobustIntegrationTest.ServerIntegrationInstance Server { get; init; } = default!; + public RobustIntegrationTest.ClientIntegrationInstance Client { get; init; } = default!; - public PoolTestLogHandler ServerLogHandler { get; init; } - public PoolTestLogHandler ClientLogHandler { get; init; } + public PoolTestLogHandler ServerLogHandler { get; init; } = default!; + public PoolTestLogHandler ClientLogHandler { get; init; } = default!; + + private Dictionary> _loadedPrototypes = new(); + private HashSet _loadedEntityPrototypes = new(); public void Kill() { @@ -932,6 +900,57 @@ public sealed class Pair ServerLogHandler.ActivateContext(testOut); ClientLogHandler.ActivateContext(testOut); } + + public async Task LoadPrototypes(List prototypes) + { + await LoadPrototypes(Server, prototypes); + await LoadPrototypes(Client, prototypes); + } + + private async Task LoadPrototypes(RobustIntegrationTest.IntegrationInstance instance, List prototypes) + { + var changed = new Dictionary>(); + var protoMan = instance.ResolveDependency(); + foreach (var file in prototypes) + { + protoMan.LoadString(file, changed: changed); + } + + await instance.WaitPost(() => protoMan.ReloadPrototypes(changed)); + + foreach (var (kind, ids) in changed) + { + _loadedPrototypes.GetOrNew(kind).UnionWith(ids); + } + + if (_loadedPrototypes.TryGetValue(typeof(EntityPrototype), out var entIds)) + _loadedEntityPrototypes.UnionWith(entIds); + } + + public bool IsTestPrototype(EntityPrototype proto) + { + return _loadedEntityPrototypes.Contains(proto.ID); + } + + public bool IsTestEntityPrototype(string id) + { + return _loadedEntityPrototypes.Contains(id); + } + + public bool IsTestPrototype(string id) where TPrototype : IPrototype + { + return IsTestPrototype(typeof(TPrototype), id); + } + + public bool IsTestPrototype(TPrototype proto) where TPrototype : IPrototype + { + return IsTestPrototype(typeof(TPrototype), proto.ID); + } + + public bool IsTestPrototype(Type kind, string id) + { + return _loadedPrototypes.TryGetValue(kind, out var ids) && ids.Contains(id); + } } /// @@ -941,8 +960,8 @@ public sealed class PairTracker : IAsyncDisposable { private readonly TextWriter _testOut; private int _disposed; - public Stopwatch UsageWatch { get; set; } - public Pair Pair { get; init; } + public Stopwatch UsageWatch { get; set; } = default!; + public Pair Pair { get; init; } = default!; public PairTracker(TextWriter testOut) { diff --git a/Content.IntegrationTests/PoolManagerTestEventHandler.cs b/Content.IntegrationTests/PoolManagerTestEventHandler.cs index e21ba8b175..d37dffff50 100644 --- a/Content.IntegrationTests/PoolManagerTestEventHandler.cs +++ b/Content.IntegrationTests/PoolManagerTestEventHandler.cs @@ -9,9 +9,11 @@ public sealed class PoolManagerTestEventHandler // This value is completely arbitrary. private static TimeSpan MaximumTotalTestingTimeLimit => TimeSpan.FromMinutes(20); private static TimeSpan HardStopTimeLimit => MaximumTotalTestingTimeLimit.Add(TimeSpan.FromMinutes(1)); + [OneTimeSetUp] public void Setup() { + PoolManager.Startup(typeof(PoolManagerTestEventHandler).Assembly); // If the tests seem to be stuck, we try to end it semi-nicely _ = Task.Delay(MaximumTotalTestingTimeLimit).ContinueWith(_ => { diff --git a/Content.IntegrationTests/TestPrototypesAttribute.cs b/Content.IntegrationTests/TestPrototypesAttribute.cs new file mode 100644 index 0000000000..fc533927a4 --- /dev/null +++ b/Content.IntegrationTests/TestPrototypesAttribute.cs @@ -0,0 +1,9 @@ +namespace Content.IntegrationTests; + +/// +/// Attribute that indicates that a string contains yaml prototype data that should be loaded by integration tests. +/// +[AttributeUsage(AttributeTargets.Field)] +public sealed class TestPrototypesAttribute : Attribute +{ +} diff --git a/Content.IntegrationTests/Tests/Atmos/AlarmThresholdTest.cs b/Content.IntegrationTests/Tests/Atmos/AlarmThresholdTest.cs index 663cb27758..e2ccddbeae 100644 --- a/Content.IntegrationTests/Tests/Atmos/AlarmThresholdTest.cs +++ b/Content.IntegrationTests/Tests/Atmos/AlarmThresholdTest.cs @@ -7,9 +7,10 @@ namespace Content.IntegrationTests.Tests.Atmos [TestOf(typeof(AtmosAlarmThreshold))] public sealed class AlarmThresholdTest { + [TestPrototypes] private const string Prototypes = @" - type: alarmThreshold - id: testThreshold + id: AlarmThresholdTestDummy upperBound: !type:AlarmThresholdSetting threshold: 5 lowerBound: !type:AlarmThresholdSetting @@ -23,7 +24,7 @@ namespace Content.IntegrationTests.Tests.Atmos [Test] public async Task TestAlarmThreshold() { - await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true, ExtraPrototypes = Prototypes }); + await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true }); var server = pairTracker.Pair.Server; var prototypeManager = server.ResolveDependency(); @@ -31,7 +32,7 @@ namespace Content.IntegrationTests.Tests.Atmos await server.WaitPost(() => { - threshold = prototypeManager.Index("testThreshold"); + threshold = prototypeManager.Index("AlarmThresholdTestDummy"); }); await server.WaitAssertion(() => diff --git a/Content.IntegrationTests/Tests/Body/LegTest.cs b/Content.IntegrationTests/Tests/Body/LegTest.cs index 5932c4211a..4b75d72073 100644 --- a/Content.IntegrationTests/Tests/Body/LegTest.cs +++ b/Content.IntegrationTests/Tests/Body/LegTest.cs @@ -14,6 +14,7 @@ namespace Content.IntegrationTests.Tests.Body [TestOf(typeof(BodyComponent))] public sealed class LegTest { + [TestPrototypes] private const string Prototypes = @" - type: entity name: HumanBodyAndAppearanceDummy @@ -30,8 +31,7 @@ namespace Content.IntegrationTests.Tests.Body { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; diff --git a/Content.IntegrationTests/Tests/Body/LungTest.cs b/Content.IntegrationTests/Tests/Body/LungTest.cs index e612245661..087a85fe66 100644 --- a/Content.IntegrationTests/Tests/Body/LungTest.cs +++ b/Content.IntegrationTests/Tests/Body/LungTest.cs @@ -19,10 +19,11 @@ namespace Content.IntegrationTests.Tests.Body [TestOf(typeof(LungSystem))] public sealed class LungTest { + [TestPrototypes] private const string Prototypes = @" - type: entity - name: HumanBodyDummy - id: HumanBodyDummy + name: HumanLungDummy + id: HumanLungDummy components: - type: SolutionContainerManager - type: Body @@ -54,8 +55,7 @@ namespace Content.IntegrationTests.Tests.Body // --- Setup await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; @@ -104,7 +104,7 @@ namespace Content.IntegrationTests.Tests.Body { var coords = new Vector2(0.5f, -1f); var coordinates = new EntityCoordinates(grid.Value, coords); - human = entityManager.SpawnEntity("HumanBodyDummy", coordinates); + human = entityManager.SpawnEntity("HumanLungDummy", coordinates); respSys = entityManager.System(); metaSys = entityManager.System(); relevantAtmos = entityManager.GetComponent(grid.Value); @@ -143,8 +143,7 @@ namespace Content.IntegrationTests.Tests.Body { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; @@ -179,7 +178,7 @@ namespace Content.IntegrationTests.Tests.Body var center = new Vector2(0.5f, 0.5f); var coordinates = new EntityCoordinates(grid.Value, center); - human = entityManager.SpawnEntity("HumanBodyDummy", coordinates); + human = entityManager.SpawnEntity("HumanLungDummy", coordinates); var mixture = entityManager.System().GetContainingMixture(human); #pragma warning disable NUnit2045 diff --git a/Content.IntegrationTests/Tests/Body/SaveLoadReparentTest.cs b/Content.IntegrationTests/Tests/Body/SaveLoadReparentTest.cs index c6a13a5861..737fff3662 100644 --- a/Content.IntegrationTests/Tests/Body/SaveLoadReparentTest.cs +++ b/Content.IntegrationTests/Tests/Body/SaveLoadReparentTest.cs @@ -11,6 +11,7 @@ namespace Content.IntegrationTests.Tests.Body; [TestFixture] public sealed class SaveLoadReparentTest { + [TestPrototypes] private const string Prototypes = @" - type: entity name: HumanBodyDummy @@ -25,8 +26,7 @@ public sealed class SaveLoadReparentTest { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; diff --git a/Content.IntegrationTests/Tests/Buckle/BuckleTest.cs b/Content.IntegrationTests/Tests/Buckle/BuckleTest.cs index ebf175b81c..9de0c02f5e 100644 --- a/Content.IntegrationTests/Tests/Buckle/BuckleTest.cs +++ b/Content.IntegrationTests/Tests/Buckle/BuckleTest.cs @@ -21,7 +21,8 @@ namespace Content.IntegrationTests.Tests.Buckle private const string StrapDummyId = "StrapDummy"; private const string ItemDummyId = "ItemDummy"; - private static readonly string Prototypes = $@" + [TestPrototypes] + private const string Prototypes = $@" - type: entity name: {BuckleDummyId} id: {BuckleDummyId} @@ -49,7 +50,7 @@ namespace Content.IntegrationTests.Tests.Buckle public async Task BuckleUnbuckleCooldownRangeTest() { await using var pairTracker = - await PoolManager.GetServerClient(new PoolSettings { ExtraPrototypes = Prototypes }); + await PoolManager.GetServerClient(); var server = pairTracker.Pair.Server; var testMap = await PoolManager.CreateTestMap(pairTracker); @@ -244,8 +245,7 @@ namespace Content.IntegrationTests.Tests.Buckle { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; @@ -341,8 +341,7 @@ namespace Content.IntegrationTests.Tests.Buckle { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; diff --git a/Content.IntegrationTests/Tests/CargoTest.cs b/Content.IntegrationTests/Tests/CargoTest.cs index 88c96bb04b..9af6ffcec7 100644 --- a/Content.IntegrationTests/Tests/CargoTest.cs +++ b/Content.IntegrationTests/Tests/CargoTest.cs @@ -109,6 +109,7 @@ public sealed class CargoTest var protoIds = protoManager.EnumeratePrototypes() .Where(p => !p.Abstract) + .Where(p => !pairTracker.Pair.IsTestPrototype(p)) .Where(p => !p.Components.ContainsKey("MapGrid")) // Grids are not for sale. .Select(p => p.ID) .ToList(); @@ -144,10 +145,9 @@ public sealed class CargoTest await pairTracker.CleanReturnAsync(); } - [Test] - public async Task StackPrice() - { - const string stackProto = @" + + [TestPrototypes] + private const string StackProto = @" - type: entity id: A @@ -165,7 +165,11 @@ public sealed class CargoTest count: 5 "; - await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true, ExtraPrototypes = stackProto }); + [Test] + public async Task StackPrice() + { + + await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true } ); var server = pairTracker.Pair.Server; var entManager = server.ResolveDependency(); diff --git a/Content.IntegrationTests/Tests/Chemistry/SolutionSystemTests.cs b/Content.IntegrationTests/Tests/Chemistry/SolutionSystemTests.cs index 0372e5ca88..d0bd8718e6 100644 --- a/Content.IntegrationTests/Tests/Chemistry/SolutionSystemTests.cs +++ b/Content.IntegrationTests/Tests/Chemistry/SolutionSystemTests.cs @@ -14,6 +14,7 @@ namespace Content.IntegrationTests.Tests.Chemistry; [TestOf(typeof(SolutionContainerSystem))] public sealed class SolutionSystemTests { + [TestPrototypes] private const string Prototypes = @" - type: entity id: SolutionTarget @@ -47,8 +48,7 @@ public sealed class SolutionSystemTests { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; @@ -95,8 +95,7 @@ public sealed class SolutionSystemTests { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; @@ -143,8 +142,7 @@ public sealed class SolutionSystemTests { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; @@ -202,8 +200,7 @@ public sealed class SolutionSystemTests { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; @@ -241,7 +238,7 @@ public sealed class SolutionSystemTests [Test] public async Task TestTemperatureCalculations() { - await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true, ExtraPrototypes = Prototypes }); + await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true }); var server = pairTracker.Pair.Server; var protoMan = server.ResolveDependency(); const float temp = 100.0f; diff --git a/Content.IntegrationTests/Tests/Chemistry/TryAllReactionsTest.cs b/Content.IntegrationTests/Tests/Chemistry/TryAllReactionsTest.cs index 37a9c7c162..7758761923 100644 --- a/Content.IntegrationTests/Tests/Chemistry/TryAllReactionsTest.cs +++ b/Content.IntegrationTests/Tests/Chemistry/TryAllReactionsTest.cs @@ -13,6 +13,7 @@ namespace Content.IntegrationTests.Tests.Chemistry [TestOf(typeof(ReactionPrototype))] public sealed class TryAllReactionsTest { + [TestPrototypes] private const string Prototypes = @" - type: entity id: TestSolutionContainer @@ -22,13 +23,13 @@ namespace Content.IntegrationTests.Tests.Chemistry beaker: maxVol: 50 canMix: true"; + [Test] public async Task TryAllTest() { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; diff --git a/Content.IntegrationTests/Tests/Commands/RejuvenateTest.cs b/Content.IntegrationTests/Tests/Commands/RejuvenateTest.cs index 1fbc6c7532..c43ea955f6 100644 --- a/Content.IntegrationTests/Tests/Commands/RejuvenateTest.cs +++ b/Content.IntegrationTests/Tests/Commands/RejuvenateTest.cs @@ -15,6 +15,7 @@ namespace Content.IntegrationTests.Tests.Commands [TestOf(typeof(RejuvenateSystem))] public sealed class RejuvenateTest { + [TestPrototypes] private const string Prototypes = @" - type: entity name: DamageableDummy @@ -34,8 +35,7 @@ namespace Content.IntegrationTests.Tests.Commands { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; var entManager = server.ResolveDependency(); diff --git a/Content.IntegrationTests/Tests/Construction/ConstructionPrototypeTest.cs b/Content.IntegrationTests/Tests/Construction/ConstructionPrototypeTest.cs index 7e196526bb..64978ba30c 100644 --- a/Content.IntegrationTests/Tests/Construction/ConstructionPrototypeTest.cs +++ b/Content.IntegrationTests/Tests/Construction/ConstructionPrototypeTest.cs @@ -101,7 +101,7 @@ namespace Content.IntegrationTests.Tests.Construction { foreach (var proto in protoMan.EnumeratePrototypes()) { - if (proto.Abstract || !proto.Components.TryGetValue(name, out var reg)) + if (proto.Abstract || pairTracker.Pair.IsTestPrototype(proto) || !proto.Components.TryGetValue(name, out var reg)) continue; var comp = (ConstructionComponent) reg.Component; diff --git a/Content.IntegrationTests/Tests/ContainerOcclusionTest.cs b/Content.IntegrationTests/Tests/ContainerOcclusionTest.cs index 5596cb2e6d..fac37b0eeb 100644 --- a/Content.IntegrationTests/Tests/ContainerOcclusionTest.cs +++ b/Content.IntegrationTests/Tests/ContainerOcclusionTest.cs @@ -9,6 +9,7 @@ namespace Content.IntegrationTests.Tests { public sealed class ContainerOcclusionTest { + [TestPrototypes] private const string Prototypes = @" - type: entity id: ContainerOcclusionA @@ -33,7 +34,7 @@ namespace Content.IntegrationTests.Tests [Test] public async Task TestA() { - await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { ExtraPrototypes = Prototypes }); + await using var pairTracker = await PoolManager.GetServerClient(); var s = pairTracker.Pair.Server; var c = pairTracker.Pair.Client; @@ -73,7 +74,7 @@ namespace Content.IntegrationTests.Tests [Test] public async Task TestB() { - await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { ExtraPrototypes = Prototypes }); + await using var pairTracker = await PoolManager.GetServerClient(); var s = pairTracker.Pair.Server; var c = pairTracker.Pair.Client; @@ -113,7 +114,7 @@ namespace Content.IntegrationTests.Tests [Test] public async Task TestAb() { - await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { ExtraPrototypes = Prototypes }); + await using var pairTracker = await PoolManager.GetServerClient(); var s = pairTracker.Pair.Server; var c = pairTracker.Pair.Client; diff --git a/Content.IntegrationTests/Tests/Damageable/DamageableTest.cs b/Content.IntegrationTests/Tests/Damageable/DamageableTest.cs index 7099eb4326..8374b0a22e 100644 --- a/Content.IntegrationTests/Tests/Damageable/DamageableTest.cs +++ b/Content.IntegrationTests/Tests/Damageable/DamageableTest.cs @@ -14,7 +14,8 @@ namespace Content.IntegrationTests.Tests.Damageable [TestOf(typeof(DamageableSystem))] public sealed class DamageableTest { - public const string Prototypes = @" + [TestPrototypes] + private const string Prototypes = @" # Define some damage groups - type: damageType id: TestDamage1 @@ -74,8 +75,7 @@ namespace Content.IntegrationTests.Tests.Damageable { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; diff --git a/Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs b/Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs index 8b5452a507..5932cb4ee8 100644 --- a/Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs +++ b/Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs @@ -20,8 +20,7 @@ namespace Content.IntegrationTests.Tests.Destructible { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; diff --git a/Content.IntegrationTests/Tests/Destructible/DestructibleDamageTypeTest.cs b/Content.IntegrationTests/Tests/Destructible/DestructibleDamageTypeTest.cs index 8352585a39..da98c3f633 100644 --- a/Content.IntegrationTests/Tests/Destructible/DestructibleDamageTypeTest.cs +++ b/Content.IntegrationTests/Tests/Destructible/DestructibleDamageTypeTest.cs @@ -17,8 +17,7 @@ namespace Content.IntegrationTests.Tests.Destructible { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; diff --git a/Content.IntegrationTests/Tests/Destructible/DestructibleDestructionTest.cs b/Content.IntegrationTests/Tests/Destructible/DestructibleDestructionTest.cs index 0373f0d5ed..5add6f37f8 100644 --- a/Content.IntegrationTests/Tests/Destructible/DestructibleDestructionTest.cs +++ b/Content.IntegrationTests/Tests/Destructible/DestructibleDestructionTest.cs @@ -16,8 +16,7 @@ namespace Content.IntegrationTests.Tests.Destructible { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; diff --git a/Content.IntegrationTests/Tests/Destructible/DestructibleTestPrototypes.cs b/Content.IntegrationTests/Tests/Destructible/DestructibleTestPrototypes.cs index a5e27a7985..a4f623e8b3 100644 --- a/Content.IntegrationTests/Tests/Destructible/DestructibleTestPrototypes.cs +++ b/Content.IntegrationTests/Tests/Destructible/DestructibleTestPrototypes.cs @@ -8,7 +8,8 @@ namespace Content.IntegrationTests.Tests.Destructible public const string DestructibleDamageTypeEntityId = "DestructibleTestsDestructibleDamageTypeEntity"; public const string DestructibleDamageGroupEntityId = "DestructibleTestsDestructibleDamageGroupEntity"; - public static readonly string Prototypes = $@" + [TestPrototypes] + public const string DamagePrototypes = $@" - type: damageType id: TestBlunt diff --git a/Content.IntegrationTests/Tests/Destructible/DestructibleThresholdActivationTest.cs b/Content.IntegrationTests/Tests/Destructible/DestructibleThresholdActivationTest.cs index 519040ab46..f3e5a001bd 100644 --- a/Content.IntegrationTests/Tests/Destructible/DestructibleThresholdActivationTest.cs +++ b/Content.IntegrationTests/Tests/Destructible/DestructibleThresholdActivationTest.cs @@ -22,8 +22,7 @@ namespace Content.IntegrationTests.Tests.Destructible { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; diff --git a/Content.IntegrationTests/Tests/DeviceNetwork/DeviceNetworkTest.cs b/Content.IntegrationTests/Tests/DeviceNetwork/DeviceNetworkTest.cs index 4ac8111a50..7dee70a101 100644 --- a/Content.IntegrationTests/Tests/DeviceNetwork/DeviceNetworkTest.cs +++ b/Content.IntegrationTests/Tests/DeviceNetwork/DeviceNetworkTest.cs @@ -15,6 +15,7 @@ namespace Content.IntegrationTests.Tests.DeviceNetwork [TestOf(typeof(WirelessNetworkComponent))] public sealed class DeviceNetworkTest { + [TestPrototypes] private const string Prototypes = @" - type: entity name: DummyNetworkDevice @@ -36,8 +37,8 @@ namespace Content.IntegrationTests.Tests.DeviceNetwork - type: ApcPowerReceiver - type: entity - name: DummyWirelessNetworkDevice - id: DummyWirelessNetworkDevice + name: WirelessNetworkDeviceDummy + id: WirelessNetworkDeviceDummy components: - type: DeviceNetwork transmitFrequency: 100 @@ -52,8 +53,7 @@ namespace Content.IntegrationTests.Tests.DeviceNetwork { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; @@ -116,8 +116,7 @@ namespace Content.IntegrationTests.Tests.DeviceNetwork { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; var testMap = await PoolManager.CreateTestMap(pairTracker); @@ -144,7 +143,7 @@ namespace Content.IntegrationTests.Tests.DeviceNetwork await server.WaitAssertion(() => { - device1 = entityManager.SpawnEntity("DummyWirelessNetworkDevice", coordinates); + device1 = entityManager.SpawnEntity("WirelessNetworkDeviceDummy", coordinates); Assert.Multiple(() => { @@ -157,7 +156,7 @@ namespace Content.IntegrationTests.Tests.DeviceNetwork Assert.That(networkComponent1.Address, Is.Not.EqualTo(string.Empty)); }); - device2 = entityManager.SpawnEntity("DummyWirelessNetworkDevice", new MapCoordinates(new Vector2(0, 50), testMap.MapId)); + device2 = entityManager.SpawnEntity("WirelessNetworkDeviceDummy", new MapCoordinates(new Vector2(0, 50), testMap.MapId)); Assert.That(entityManager.TryGetComponent(device2, out networkComponent2), Is.True); Assert.Multiple(() => @@ -205,8 +204,7 @@ namespace Content.IntegrationTests.Tests.DeviceNetwork { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; var testMap = await PoolManager.CreateTestMap(pairTracker); diff --git a/Content.IntegrationTests/Tests/Disposal/DisposalUnitTest.cs b/Content.IntegrationTests/Tests/Disposal/DisposalUnitTest.cs index 6954dc1215..fca1cbc2c3 100644 --- a/Content.IntegrationTests/Tests/Disposal/DisposalUnitTest.cs +++ b/Content.IntegrationTests/Tests/Disposal/DisposalUnitTest.cs @@ -72,10 +72,11 @@ namespace Content.IntegrationTests.Tests.Disposal }); } + [TestPrototypes] private const string Prototypes = @" - type: entity - name: HumanDummy - id: HumanDummy + name: HumanDisposalDummy + id: HumanDisposalDummy components: - type: Body prototype: Human @@ -148,8 +149,7 @@ namespace Content.IntegrationTests.Tests.Disposal { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; @@ -171,7 +171,7 @@ namespace Content.IntegrationTests.Tests.Disposal { // Spawn the entities var coordinates = testMap.GridCoords; - human = entityManager.SpawnEntity("HumanDummy", coordinates); + human = entityManager.SpawnEntity("HumanDisposalDummy", coordinates); wrench = entityManager.SpawnEntity("WrenchDummy", coordinates); disposalUnit = entityManager.SpawnEntity("DisposalUnitDummy", coordinates); disposalTrunk = entityManager.SpawnEntity("DisposalTrunkDummy", diff --git a/Content.IntegrationTests/Tests/DoAfter/DoAfterServerTest.cs b/Content.IntegrationTests/Tests/DoAfter/DoAfterServerTest.cs index efcf12e3db..7554c1be98 100644 --- a/Content.IntegrationTests/Tests/DoAfter/DoAfterServerTest.cs +++ b/Content.IntegrationTests/Tests/DoAfter/DoAfterServerTest.cs @@ -12,10 +12,11 @@ namespace Content.IntegrationTests.Tests.DoAfter [TestOf(typeof(DoAfterComponent))] public sealed class DoAfterServerTest { + [TestPrototypes] private const string Prototypes = @" - type: entity - name: Dummy - id: Dummy + name: DoAfterDummy + id: DoAfterDummy components: - type: DoAfter "; @@ -60,8 +61,7 @@ namespace Content.IntegrationTests.Tests.DoAfter { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; await server.WaitIdleAsync(); @@ -75,7 +75,7 @@ namespace Content.IntegrationTests.Tests.DoAfter await server.WaitPost(() => { var tickTime = 1.0f / timing.TickRate; - var mob = entityManager.SpawnEntity("Dummy", MapCoordinates.Nullspace); + var mob = entityManager.SpawnEntity("DoAfterDummy", MapCoordinates.Nullspace); var args = new DoAfterArgs(mob, tickTime / 2, ev, null) { Broadcast = true }; #pragma warning disable NUnit2045 // Interdependent assertions. Assert.That(doAfterSystem.TryStartDoAfter(args)); @@ -94,8 +94,7 @@ namespace Content.IntegrationTests.Tests.DoAfter { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; var entityManager = server.ResolveDependency(); @@ -107,7 +106,7 @@ namespace Content.IntegrationTests.Tests.DoAfter { var tickTime = 1.0f / timing.TickRate; - var mob = entityManager.SpawnEntity("Dummy", MapCoordinates.Nullspace); + var mob = entityManager.SpawnEntity("DoAfterDummy", MapCoordinates.Nullspace); var args = new DoAfterArgs(mob, tickTime * 2, ev, null) { Broadcast = true }; if (!doAfterSystem.TryStartDoAfter(args, out var id)) diff --git a/Content.IntegrationTests/Tests/Doors/AirlockTest.cs b/Content.IntegrationTests/Tests/Doors/AirlockTest.cs index 15a0e800b1..493b7be8c8 100644 --- a/Content.IntegrationTests/Tests/Doors/AirlockTest.cs +++ b/Content.IntegrationTests/Tests/Doors/AirlockTest.cs @@ -13,10 +13,11 @@ namespace Content.IntegrationTests.Tests.Doors [TestOf(typeof(AirlockComponent))] public sealed class AirlockTest { + [TestPrototypes] private const string Prototypes = @" - type: entity - name: PhysicsDummy - id: PhysicsDummy + name: AirlockPhysicsDummy + id: AirlockPhysicsDummy components: - type: Physics bodyType: Dynamic @@ -54,8 +55,7 @@ namespace Content.IntegrationTests.Tests.Doors { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; @@ -117,8 +117,7 @@ namespace Content.IntegrationTests.Tests.Doors { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; @@ -130,24 +129,24 @@ namespace Content.IntegrationTests.Tests.Doors var xformSystem = entityManager.System(); PhysicsComponent physBody = null; - EntityUid physicsDummy = default; + EntityUid AirlockPhysicsDummy = default; EntityUid airlock = default; DoorComponent doorComponent = null; - var physicsDummyStartingX = -1; + var AirlockPhysicsDummyStartingX = -1; await server.WaitAssertion(() => { var mapId = mapManager.CreateMap(); - var humanCoordinates = new MapCoordinates(new Vector2(physicsDummyStartingX, 0), mapId); - physicsDummy = entityManager.SpawnEntity("PhysicsDummy", humanCoordinates); + var humanCoordinates = new MapCoordinates(new Vector2(AirlockPhysicsDummyStartingX, 0), mapId); + AirlockPhysicsDummy = entityManager.SpawnEntity("AirlockPhysicsDummy", humanCoordinates); airlock = entityManager.SpawnEntity("AirlockDummy", new MapCoordinates(new Vector2(0, 0), mapId)); Assert.Multiple(() => { - Assert.That(entityManager.TryGetComponent(physicsDummy, out physBody), Is.True); + Assert.That(entityManager.TryGetComponent(AirlockPhysicsDummy, out physBody), Is.True); Assert.That(entityManager.TryGetComponent(airlock, out doorComponent), Is.True); }); Assert.That(doorComponent.State, Is.EqualTo(DoorState.Closed)); @@ -159,7 +158,7 @@ namespace Content.IntegrationTests.Tests.Doors await server.WaitAssertion(() => Assert.That(physBody, Is.Not.EqualTo(null))); await server.WaitPost(() => { - physicsSystem.SetLinearVelocity(physicsDummy, new Vector2(0.5f, 0f), body: physBody); + physicsSystem.SetLinearVelocity(AirlockPhysicsDummy, new Vector2(0.5f, 0f), body: physBody); }); for (var i = 0; i < 240; i += 10) @@ -178,12 +177,12 @@ namespace Content.IntegrationTests.Tests.Doors // Sloth: Okay I'm sorry but I hate having to rewrite tests for every refactor // If you see this yell at me in discord so I can continue to pretend this didn't happen. // REMINDER THAT I STILL HAVE TO FIX THIS TEST EVERY OTHER PHYSICS PR - // Assert.That(physicsDummy.Transform.MapPosition.X, Is.GreaterThan(physicsDummyStartingX)); + // Assert.That(AirlockPhysicsDummy.Transform.MapPosition.X, Is.GreaterThan(AirlockPhysicsDummyStartingX)); // Blocked by the airlock await server.WaitAssertion(() => { - Assert.That(Math.Abs(xformSystem.GetWorldPosition(physicsDummy).X - 1), Is.GreaterThan(0.01f)); + Assert.That(Math.Abs(xformSystem.GetWorldPosition(AirlockPhysicsDummy).X - 1), Is.GreaterThan(0.01f)); }); await pairTracker.CleanReturnAsync(); } diff --git a/Content.IntegrationTests/Tests/DummyIconTest.cs b/Content.IntegrationTests/Tests/DummyIconTest.cs index 56a183a42c..af113592a2 100644 --- a/Content.IntegrationTests/Tests/DummyIconTest.cs +++ b/Content.IntegrationTests/Tests/DummyIconTest.cs @@ -21,7 +21,7 @@ namespace Content.IntegrationTests.Tests { foreach (var proto in prototypeManager.EnumeratePrototypes()) { - if (proto.NoSpawn || proto.Abstract || !proto.Components.ContainsKey("Sprite")) + if (proto.NoSpawn || proto.Abstract || pairTracker.Pair.IsTestPrototype(proto) || !proto.Components.ContainsKey("Sprite")) continue; Assert.DoesNotThrow(() => diff --git a/Content.IntegrationTests/Tests/EntityTest.cs b/Content.IntegrationTests/Tests/EntityTest.cs index d1cacf1833..0ba948aefc 100644 --- a/Content.IntegrationTests/Tests/EntityTest.cs +++ b/Content.IntegrationTests/Tests/EntityTest.cs @@ -34,6 +34,7 @@ namespace Content.IntegrationTests.Tests var protoIds = prototypeMan .EnumeratePrototypes() .Where(p => !p.Abstract) + .Where(p => !pairTracker.Pair.IsTestPrototype(p)) .Where(p => !p.Components.ContainsKey("MapGrid")) // This will smash stuff otherwise. .Select(p => p.ID) .ToList(); @@ -90,6 +91,7 @@ namespace Content.IntegrationTests.Tests var protoIds = prototypeMan .EnumeratePrototypes() .Where(p => !p.Abstract) + .Where(p => !pairTracker.Pair.IsTestPrototype(p)) .Where(p => !p.Components.ContainsKey("MapGrid")) // This will smash stuff otherwise. .Select(p => p.ID) .ToList(); @@ -146,6 +148,7 @@ namespace Content.IntegrationTests.Tests var protoIds = prototypeMan .EnumeratePrototypes() .Where(p => !p.Abstract) + .Where(p => !pairTracker.Pair.IsTestPrototype(p)) .Where(p => !p.Components.ContainsKey("MapGrid")) // This will smash stuff otherwise. .Select(p => p.ID) .ToList(); diff --git a/Content.IntegrationTests/Tests/GameObjects/Components/ActionBlocking/HandCuffTest.cs b/Content.IntegrationTests/Tests/GameObjects/Components/ActionBlocking/HandCuffTest.cs index f833451461..3eee956cb3 100644 --- a/Content.IntegrationTests/Tests/GameObjects/Components/ActionBlocking/HandCuffTest.cs +++ b/Content.IntegrationTests/Tests/GameObjects/Components/ActionBlocking/HandCuffTest.cs @@ -16,10 +16,11 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking [TestOf(typeof(HandcuffComponent))] public sealed class HandCuffTest { + [TestPrototypes] private const string Prototypes = @" - type: entity - name: HumanDummy - id: HumanDummy + name: HumanHandcuffDummy + id: HumanHandcuffDummy components: - type: Cuffable - type: Hands @@ -38,8 +39,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; @@ -64,8 +64,8 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking var xformQuery = entityManager.GetEntityQuery(); // Spawn the entities - human = entityManager.SpawnEntity("HumanDummy", coordinates); - otherHuman = entityManager.SpawnEntity("HumanDummy", coordinates); + human = entityManager.SpawnEntity("HumanHandcuffDummy", coordinates); + otherHuman = entityManager.SpawnEntity("HumanHandcuffDummy", coordinates); cuffs = entityManager.SpawnEntity("HandcuffsDummy", coordinates); secondCuffs = entityManager.SpawnEntity("HandcuffsDummy", coordinates); diff --git a/Content.IntegrationTests/Tests/Gravity/WeightlessStatusTests.cs b/Content.IntegrationTests/Tests/Gravity/WeightlessStatusTests.cs index 5af8861c56..91bf9e7b03 100644 --- a/Content.IntegrationTests/Tests/Gravity/WeightlessStatusTests.cs +++ b/Content.IntegrationTests/Tests/Gravity/WeightlessStatusTests.cs @@ -9,18 +9,19 @@ namespace Content.IntegrationTests.Tests.Gravity [TestOf(typeof(GravityGeneratorComponent))] public sealed class WeightlessStatusTests { + [TestPrototypes] private const string Prototypes = @" - type: entity - name: HumanDummy - id: HumanDummy + name: HumanWeightlessDummy + id: HumanWeightlessDummy components: - type: Alerts - type: Physics bodyType: Dynamic - type: entity - name: GravityGeneratorDummy - id: GravityGeneratorDummy + name: WeightlessGravityGeneratorDummy + id: WeightlessGravityGeneratorDummy components: - type: GravityGenerator chargeRate: 1000000000 # Set this really high so it discharges in a single tick. @@ -34,8 +35,7 @@ namespace Content.IntegrationTests.Tests.Gravity { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; @@ -48,7 +48,7 @@ namespace Content.IntegrationTests.Tests.Gravity await server.WaitAssertion(() => { - human = entityManager.SpawnEntity("HumanDummy", testMap.GridCoords); + human = entityManager.SpawnEntity("HumanWeightlessDummy", testMap.GridCoords); Assert.That(entityManager.TryGetComponent(human, out AlertsComponent alerts)); }); @@ -61,7 +61,7 @@ namespace Content.IntegrationTests.Tests.Gravity // No gravity without a gravity generator Assert.That(alertsSystem.IsShowingAlert(human, AlertType.Weightless)); - generatorUid = entityManager.SpawnEntity("GravityGeneratorDummy", entityManager.GetComponent(human).Coordinates); + generatorUid = entityManager.SpawnEntity("WeightlessGravityGeneratorDummy", entityManager.GetComponent(human).Coordinates); }); // Let WeightlessSystem and GravitySystem tick diff --git a/Content.IntegrationTests/Tests/GravityGridTest.cs b/Content.IntegrationTests/Tests/GravityGridTest.cs index 62df17d49f..b426671f04 100644 --- a/Content.IntegrationTests/Tests/GravityGridTest.cs +++ b/Content.IntegrationTests/Tests/GravityGridTest.cs @@ -15,10 +15,11 @@ namespace Content.IntegrationTests.Tests [TestOf(typeof(GravityGeneratorComponent))] public sealed class GravityGridTest { + [TestPrototypes] private const string Prototypes = @" - type: entity - name: GravityGeneratorDummy - id: GravityGeneratorDummy + name: GridGravityGeneratorDummy + id: GridGravityGeneratorDummy components: - type: GravityGenerator chargeRate: 1000000000 # Set this really high so it discharges in a single tick. @@ -31,8 +32,7 @@ namespace Content.IntegrationTests.Tests { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; @@ -56,7 +56,7 @@ namespace Content.IntegrationTests.Tests grid1Entity = grid1.Owner; grid2Entity = grid2.Owner; - generator = entityMan.SpawnEntity("GravityGeneratorDummy", grid2.ToCoordinates()); + generator = entityMan.SpawnEntity("GridGravityGeneratorDummy", grid2.ToCoordinates()); Assert.Multiple(() => { Assert.That(entityMan.HasComponent(generator)); diff --git a/Content.IntegrationTests/Tests/HumanInventoryUniformSlotsTest.cs b/Content.IntegrationTests/Tests/HumanInventoryUniformSlotsTest.cs index df5ad79099..a5e2b967a4 100644 --- a/Content.IntegrationTests/Tests/HumanInventoryUniformSlotsTest.cs +++ b/Content.IntegrationTests/Tests/HumanInventoryUniformSlotsTest.cs @@ -9,10 +9,11 @@ namespace Content.IntegrationTests.Tests [TestFixture] public sealed class HumanInventoryUniformSlotsTest { + [TestPrototypes] private const string Prototypes = @" - type: entity - name: HumanDummy - id: HumanDummy + name: HumanUniformDummy + id: HumanUniformDummy components: - type: Inventory - type: ContainerContainer @@ -54,7 +55,7 @@ namespace Content.IntegrationTests.Tests [Test] public async Task Test() { - await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true, ExtraPrototypes = Prototypes }); + await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true }); var server = pairTracker.Pair.Server; var testMap = await PoolManager.CreateTestMap(pairTracker); var coordinates = testMap.GridCoords; @@ -71,7 +72,7 @@ namespace Content.IntegrationTests.Tests { invSystem = entityMan.System(); - human = entityMan.SpawnEntity("HumanDummy", coordinates); + human = entityMan.SpawnEntity("HumanUniformDummy", coordinates); uniform = entityMan.SpawnEntity("UniformDummy", coordinates); idCard = entityMan.SpawnEntity("IDCardDummy", coordinates); pocketItem = entityMan.SpawnEntity("FlashlightDummy", coordinates); diff --git a/Content.IntegrationTests/Tests/Interaction/Click/InteractionSystemTests.cs b/Content.IntegrationTests/Tests/Interaction/Click/InteractionSystemTests.cs index d2bf1ab92b..9a01b48b62 100644 --- a/Content.IntegrationTests/Tests/Interaction/Click/InteractionSystemTests.cs +++ b/Content.IntegrationTests/Tests/Interaction/Click/InteractionSystemTests.cs @@ -17,6 +17,7 @@ namespace Content.IntegrationTests.Tests.Interaction.Click [TestOf(typeof(InteractionSystem))] public sealed class InteractionSystemTests { + [TestPrototypes] private const string Prototypes = @" - type: entity id: DummyDebugWall @@ -40,8 +41,7 @@ namespace Content.IntegrationTests.Tests.Interaction.Click { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; @@ -114,8 +114,7 @@ namespace Content.IntegrationTests.Tests.Interaction.Click { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; diff --git a/Content.IntegrationTests/Tests/Interaction/InteractionTest.cs b/Content.IntegrationTests/Tests/Interaction/InteractionTest.cs index 1ef8c11e0b..51c4b8e186 100644 --- a/Content.IntegrationTests/Tests/Interaction/InteractionTest.cs +++ b/Content.IntegrationTests/Tests/Interaction/InteractionTest.cs @@ -120,7 +120,8 @@ public abstract partial class InteractionTest // Simple mob that has one hand and can perform misc interactions. - public const string TestPrototypes = @" + [TestPrototypes] + private const string TestPrototypes = @" - type: entity id: InteractionTestMob components: @@ -139,7 +140,7 @@ public abstract partial class InteractionTest [SetUp] public virtual async Task Setup() { - PairTracker = await PoolManager.GetServerClient(new PoolSettings { ExtraPrototypes = TestPrototypes }); + PairTracker = await PoolManager.GetServerClient(); // server dependencies SEntMan = Server.ResolveDependency(); @@ -239,7 +240,7 @@ public abstract partial class InteractionTest await PairTracker.CleanReturnAsync(); await TearDown(); } - + protected virtual async Task TearDown() { } diff --git a/Content.IntegrationTests/Tests/InventoryHelpersTest.cs b/Content.IntegrationTests/Tests/InventoryHelpersTest.cs index 7dff61355d..05a5e4beba 100644 --- a/Content.IntegrationTests/Tests/InventoryHelpersTest.cs +++ b/Content.IntegrationTests/Tests/InventoryHelpersTest.cs @@ -9,6 +9,7 @@ namespace Content.IntegrationTests.Tests [TestFixture] public sealed class InventoryHelpersTest { + [TestPrototypes] private const string Prototypes = @" - type: entity name: InventoryStunnableDummy @@ -40,7 +41,7 @@ namespace Content.IntegrationTests.Tests [Test] public async Task SpawnItemInSlotTest() { - await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true, ExtraPrototypes = Prototypes }); + await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true }); var server = pairTracker.Pair.Server; var sEntities = server.ResolveDependency(); diff --git a/Content.IntegrationTests/Tests/MachineBoardTest.cs b/Content.IntegrationTests/Tests/MachineBoardTest.cs index a2c3d7b151..a239a33fd1 100644 --- a/Content.IntegrationTests/Tests/MachineBoardTest.cs +++ b/Content.IntegrationTests/Tests/MachineBoardTest.cs @@ -38,7 +38,10 @@ public sealed class MachineBoardTest await server.WaitAssertion(() => { - foreach (var p in protoMan.EnumeratePrototypes().Where(p => !p.Abstract && !_ignoredPrototypes.Contains(p.ID))) + foreach (var p in protoMan.EnumeratePrototypes() + .Where(p => !p.Abstract) + .Where(p => !pairTracker.Pair.IsTestPrototype(p)) + .Where(p => !_ignoredPrototypes.Contains(p.ID))) { if (!p.TryGetComponent(out var mbc)) continue; @@ -74,7 +77,10 @@ public sealed class MachineBoardTest await server.WaitAssertion(() => { - foreach (var p in protoMan.EnumeratePrototypes().Where(p => !p.Abstract && !_ignoredPrototypes.Contains(p.ID))) + foreach (var p in protoMan.EnumeratePrototypes() + .Where(p => !p.Abstract) + .Where(p => !pairTracker.Pair.IsTestPrototype(p)) + .Where(p => !_ignoredPrototypes.Contains(p.ID))) { if (!p.TryGetComponent(out var cbc)) continue; diff --git a/Content.IntegrationTests/Tests/MaterialArbitrageTest.cs b/Content.IntegrationTests/Tests/MaterialArbitrageTest.cs index e37f486ea0..14435a81f1 100644 --- a/Content.IntegrationTests/Tests/MaterialArbitrageTest.cs +++ b/Content.IntegrationTests/Tests/MaterialArbitrageTest.cs @@ -65,7 +65,7 @@ public sealed class MaterialArbitrageTest Dictionary constructionRecipes = new(); foreach (var proto in protoManager.EnumeratePrototypes()) { - if (proto.NoSpawn || proto.Abstract) + if (proto.NoSpawn || proto.Abstract || pairTracker.Pair.IsTestPrototype(proto)) continue; if (!proto.Components.TryGetValue(constructionName, out var destructible)) @@ -125,7 +125,7 @@ public sealed class MaterialArbitrageTest // Here we get the set of entities/materials spawned when destroying an entity. foreach (var proto in protoManager.EnumeratePrototypes()) { - if (proto.NoSpawn || proto.Abstract) + if (proto.NoSpawn || proto.Abstract || pairTracker.Pair.IsTestPrototype(proto)) continue; if (!proto.Components.TryGetValue(destructibleName, out var destructible)) @@ -290,7 +290,7 @@ public sealed class MaterialArbitrageTest Dictionary physicalCompositions = new(); foreach (var proto in protoManager.EnumeratePrototypes()) { - if (proto.NoSpawn || proto.Abstract) + if (proto.NoSpawn || proto.Abstract || pairTracker.Pair.IsTestPrototype(proto)) continue; if (!proto.Components.TryGetValue(compositionName, out var composition)) diff --git a/Content.IntegrationTests/Tests/Minds/GhostRoleTests.cs b/Content.IntegrationTests/Tests/Minds/GhostRoleTests.cs index e58d3a4ec4..3de5f80450 100644 --- a/Content.IntegrationTests/Tests/Minds/GhostRoleTests.cs +++ b/Content.IntegrationTests/Tests/Minds/GhostRoleTests.cs @@ -13,6 +13,7 @@ namespace Content.IntegrationTests.Tests.Minds; [TestFixture] public sealed class GhostRoleTests { + [TestPrototypes] private const string Prototypes = @" - type: entity id: GhostRoleTestEntity @@ -29,7 +30,7 @@ public sealed class GhostRoleTests [Test] public async Task TakeRoleAndReturn() { - await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { ExtraPrototypes = Prototypes }); + await using var pairTracker = await PoolManager.GetServerClient(); var server = pairTracker.Pair.Server; var client = pairTracker.Pair.Client; diff --git a/Content.IntegrationTests/Tests/Minds/MindTests.cs b/Content.IntegrationTests/Tests/Minds/MindTests.cs index d8aff81a82..a17b697c52 100644 --- a/Content.IntegrationTests/Tests/Minds/MindTests.cs +++ b/Content.IntegrationTests/Tests/Minds/MindTests.cs @@ -24,6 +24,7 @@ namespace Content.IntegrationTests.Tests.Minds; [TestFixture] public sealed partial class MindTests { + [TestPrototypes] private const string Prototypes = @" - type: entity id: MindTestEntityDamageable @@ -109,7 +110,7 @@ public sealed partial class MindTests [Test] public async Task TestEntityDeadWhenGibbed() { - await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true, ExtraPrototypes = Prototypes }); + await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true }); var server = pairTracker.Pair.Server; var entMan = server.ResolveDependency(); diff --git a/Content.IntegrationTests/Tests/PostMapInitTest.cs b/Content.IntegrationTests/Tests/PostMapInitTest.cs index 0952fd7817..a2f955c6ed 100644 --- a/Content.IntegrationTests/Tests/PostMapInitTest.cs +++ b/Content.IntegrationTests/Tests/PostMapInitTest.cs @@ -42,6 +42,26 @@ namespace Content.IntegrationTests.Tests "/Maps/infiltrator.yml", }; + private static readonly string[] GameMaps = + { + "Dev", + "Fland", + "Meta", + "Packed", + "Aspid", + "Cluster", + "Omega", + "Bagel", + "Origin", + "CentComm", + "Box", + "Barratry", + "Saltern", + "Core", + "Marathon", + "Kettle" + }; + /// /// Asserts that specific files have been saved as grids and not maps. /// @@ -128,53 +148,7 @@ namespace Content.IntegrationTests.Tests await pairTracker.CleanReturnAsync(); } - private static string[] GetGameMapNames() - { - Task task; - using (ExecutionContext.SuppressFlow()) - { - task = Task.Run(static async () => - { - await Task.Yield(); - await using var pairTracker = await PoolManager.GetServerClient( - new PoolSettings - { - Disconnected = true, - TestName = $"{nameof(PostMapInitTest)}.{nameof(GetGameMapNames)}" - } - ); - var server = pairTracker.Pair.Server; - var protoManager = server.ResolveDependency(); - - var maps = protoManager.EnumeratePrototypes().ToList(); - var mapNames = new List(); - var naughty = new HashSet() - { - PoolManager.TestMap, - "Infiltrator", - "Pirate", - }; - - foreach (var map in maps) - { - // AAAAAAAAAA - // Why are they stations! - if (naughty.Contains(map.ID)) - continue; - - mapNames.Add(map.ID); - } - - await pairTracker.CleanReturnAsync(); - return mapNames.ToArray(); - }); - Task.WaitAny(task); - } - - return task.GetAwaiter().GetResult(); - } - - [Test, TestCaseSource(nameof(GetGameMapNames))] + [Test, TestCaseSource(nameof(GameMaps))] public async Task GameMapsLoadableTest(string mapProto) { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true }); @@ -306,86 +280,89 @@ namespace Content.IntegrationTests.Tests await pairTracker.CleanReturnAsync(); } - /// - /// Get the non-game map maps. - /// - private static string[] GetMaps() + [Test] + public async Task AllMapsTested() { - Task task; - using (ExecutionContext.SuppressFlow()) - { - task = Task.Run(static async () => - { - await Task.Yield(); - await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { Disconnected = true }); - var server = pairTracker.Pair.Server; - var resourceManager = server.ResolveDependency(); - var protoManager = server.ResolveDependency(); + await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings {NoClient = true}); + var server = pairTracker.Pair.Server; + var protoMan = server.ResolveDependency(); - var gameMaps = protoManager.EnumeratePrototypes().Select(o => o.MapPath).ToHashSet(); + var gameMaps = protoMan.EnumeratePrototypes() + .Where(x => !pairTracker.Pair.IsTestPrototype(x)) + .Select(x => x.ID) + .ToHashSet(); - var mapFolder = new ResPath("/Maps"); - var maps = resourceManager - .ContentFindFiles(mapFolder) - .Where(filePath => filePath.Extension == "yml" && !filePath.Filename.StartsWith(".", StringComparison.Ordinal)) - .ToArray(); - var mapNames = new List(); - foreach (var map in maps) - { - var rootedPath = map.ToRootedPath(); + Assert.That(gameMaps.Remove(PoolManager.TestMap)); - // ReSharper disable once RedundantLogicalConditionalExpressionOperand - if (SkipTestMaps && rootedPath.ToString().StartsWith(TestMapsPath, StringComparison.Ordinal) || - gameMaps.Contains(map)) - { - continue; - } - mapNames.Add(rootedPath.ToString()); - } + CollectionAssert.AreEquivalent(GameMaps.ToHashSet(), gameMaps, "Game map prototype missing from test cases."); - await pairTracker.CleanReturnAsync(); - return mapNames.ToArray(); - }); - Task.WaitAny(task); - } - - return task.GetAwaiter().GetResult(); + await pairTracker.CleanReturnAsync(); } - [Test, TestCaseSource(nameof(GetMaps))] - public async Task MapsLoadableTest(string mapName) + [Test] + public async Task NonGameMapsLoadableTest() { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true }); var server = pairTracker.Pair.Server; var mapLoader = server.ResolveDependency().GetEntitySystem(); var mapManager = server.ResolveDependency(); + var resourceManager = server.ResolveDependency(); + var protoManager = server.ResolveDependency(); var cfg = server.ResolveDependency(); Assert.That(cfg.GetCVar(CCVars.GridFill), Is.False); + var gameMaps = protoManager.EnumeratePrototypes().Select(o => o.MapPath).ToHashSet(); + + var mapFolder = new ResPath("/Maps"); + var maps = resourceManager + .ContentFindFiles(mapFolder) + .Where(filePath => filePath.Extension == "yml" && !filePath.Filename.StartsWith(".", StringComparison.Ordinal)) + .ToArray(); + + var mapNames = new List(); + foreach (var map in maps) + { + if (gameMaps.Contains(map)) + continue; + + var rootedPath = map.ToRootedPath(); + if (SkipTestMaps && rootedPath.ToString().StartsWith(TestMapsPath, StringComparison.Ordinal)) + { + continue; + } + mapNames.Add(rootedPath.ToString()); + } + await server.WaitPost(() => { - var mapId = mapManager.CreateMap(); - try + Assert.Multiple(() => { - Assert.That(mapLoader.TryLoad(mapId, mapName, out _)); - } - catch (Exception ex) - { - throw new Exception($"Failed to load map {mapName}", ex); - } + foreach (var mapName in mapNames) + { + var mapId = mapManager.CreateMap(); + try + { + Assert.That(mapLoader.TryLoad(mapId, mapName, out _)); + } + catch (Exception ex) + { + throw new Exception($"Failed to load map {mapName}", ex); + } - try - { - mapManager.DeleteMap(mapId); - } - catch (Exception ex) - { - throw new Exception($"Failed to delete map {mapName}", ex); - } + try + { + mapManager.DeleteMap(mapId); + } + catch (Exception ex) + { + throw new Exception($"Failed to delete map {mapName}", ex); + } + } + }); }); - await server.WaitRunTicks(1); + await server.WaitRunTicks(1); await pairTracker.CleanReturnAsync(); } } diff --git a/Content.IntegrationTests/Tests/Power/PowerTest.cs b/Content.IntegrationTests/Tests/Power/PowerTest.cs index a3f040744b..f9305beb28 100644 --- a/Content.IntegrationTests/Tests/Power/PowerTest.cs +++ b/Content.IntegrationTests/Tests/Power/PowerTest.cs @@ -16,6 +16,7 @@ namespace Content.IntegrationTests.Tests.Power [TestFixture] public sealed class PowerTest { + [TestPrototypes] private const string Prototypes = @" - type: entity id: GeneratorDummy @@ -163,8 +164,7 @@ namespace Content.IntegrationTests.Tests.Power { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; var mapManager = server.ResolveDependency(); @@ -228,8 +228,7 @@ namespace Content.IntegrationTests.Tests.Power { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; var mapManager = server.ResolveDependency(); @@ -289,8 +288,7 @@ namespace Content.IntegrationTests.Tests.Power { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; var mapManager = server.ResolveDependency(); @@ -380,8 +378,7 @@ namespace Content.IntegrationTests.Tests.Power { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; var mapManager = server.ResolveDependency(); @@ -483,7 +480,7 @@ namespace Content.IntegrationTests.Tests.Power { // checks that batteries and supplies properly ramp down if the load is disconnected/disabled. - await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true, ExtraPrototypes = Prototypes }); + await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true }); var server = pairTracker.Pair.Server; var mapManager = server.ResolveDependency(); var entityManager = server.ResolveDependency(); @@ -581,8 +578,7 @@ namespace Content.IntegrationTests.Tests.Power { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; var mapManager = server.ResolveDependency(); @@ -641,8 +637,7 @@ namespace Content.IntegrationTests.Tests.Power { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; var mapManager = server.ResolveDependency(); @@ -722,8 +717,7 @@ namespace Content.IntegrationTests.Tests.Power { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; var mapManager = server.ResolveDependency(); @@ -803,8 +797,7 @@ namespace Content.IntegrationTests.Tests.Power { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; var mapManager = server.ResolveDependency(); @@ -901,7 +894,7 @@ namespace Content.IntegrationTests.Tests.Power [Test] public async Task TestSupplyPrioritized() { - await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true, ExtraPrototypes = Prototypes }); + await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true }); var server = pairTracker.Pair.Server; var mapManager = server.ResolveDependency(); var entityManager = server.ResolveDependency(); @@ -1001,8 +994,7 @@ namespace Content.IntegrationTests.Tests.Power { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; var mapManager = server.ResolveDependency(); @@ -1092,8 +1084,7 @@ namespace Content.IntegrationTests.Tests.Power { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; var mapManager = server.ResolveDependency(); @@ -1180,8 +1171,7 @@ namespace Content.IntegrationTests.Tests.Power { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; var mapManager = server.ResolveDependency(); @@ -1249,8 +1239,7 @@ namespace Content.IntegrationTests.Tests.Power { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; var mapManager = server.ResolveDependency(); @@ -1308,8 +1297,7 @@ namespace Content.IntegrationTests.Tests.Power { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; var mapManager = server.ResolveDependency(); diff --git a/Content.IntegrationTests/Tests/PrototypeSaveTest.cs b/Content.IntegrationTests/Tests/PrototypeSaveTest.cs index 5d458b20b4..d429f09e1f 100644 --- a/Content.IntegrationTests/Tests/PrototypeSaveTest.cs +++ b/Content.IntegrationTests/Tests/PrototypeSaveTest.cs @@ -81,6 +81,9 @@ public sealed class PrototypeSaveTest if (prototype.Abstract) continue; + if (pairTracker.Pair.IsTestPrototype(prototype)) + continue; + // Yea this test just doesn't work with this, it parents a grid to another grid and causes game logic to explode. if (prototype.Components.ContainsKey("MapGrid")) continue; diff --git a/Content.IntegrationTests/Tests/ResearchTest.cs b/Content.IntegrationTests/Tests/ResearchTest.cs index 7e7be713ce..beaf74a26e 100644 --- a/Content.IntegrationTests/Tests/ResearchTest.cs +++ b/Content.IntegrationTests/Tests/ResearchTest.cs @@ -62,6 +62,9 @@ public sealed class ResearchTest if (proto.Abstract) continue; + if (pairTracker.Pair.IsTestPrototype(proto)) + continue; + if (!proto.TryGetComponent(out var lathe)) continue; allLathes.Add(lathe); diff --git a/Content.IntegrationTests/Tests/Station/StationJobsTest.cs b/Content.IntegrationTests/Tests/Station/StationJobsTest.cs index a552384302..3063b2da7d 100644 --- a/Content.IntegrationTests/Tests/Station/StationJobsTest.cs +++ b/Content.IntegrationTests/Tests/Station/StationJobsTest.cs @@ -18,9 +18,10 @@ namespace Content.IntegrationTests.Tests.Station; [TestOf(typeof(StationJobsSystem))] public sealed class StationJobsTest { + [TestPrototypes] private const string Prototypes = @" - type: playTimeTracker - id: Dummy + id: PlayTimeDummy - type: gameMap id: FooStation @@ -43,26 +44,26 @@ public sealed class StationJobsTest - type: job id: TAssistant - playTimeTracker: Dummy + playTimeTracker: PlayTimeDummy - type: job id: TMime weight: 20 - playTimeTracker: Dummy + playTimeTracker: PlayTimeDummy - type: job id: TClown weight: -10 - playTimeTracker: Dummy + playTimeTracker: PlayTimeDummy - type: job id: TCaptain weight: 10 - playTimeTracker: Dummy + playTimeTracker: PlayTimeDummy - type: job id: TChaplain - playTimeTracker: Dummy + playTimeTracker: PlayTimeDummy "; private const int StationCount = 100; @@ -75,8 +76,7 @@ public sealed class StationJobsTest { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; @@ -153,8 +153,7 @@ public sealed class StationJobsTest { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; @@ -208,8 +207,7 @@ public sealed class StationJobsTest { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; diff --git a/Content.IntegrationTests/Tests/Tag/TagTest.cs b/Content.IntegrationTests/Tests/Tag/TagTest.cs index 0f835cca81..a36c0bc02b 100644 --- a/Content.IntegrationTests/Tests/Tag/TagTest.cs +++ b/Content.IntegrationTests/Tests/Tag/TagTest.cs @@ -15,14 +15,15 @@ namespace Content.IntegrationTests.Tests.Tag private const string TagEntityId = "TagTestDummy"; // Register these three into the prototype manager - private const string StartingTag = "A"; - private const string AddedTag = "EIOU"; - private const string UnusedTag = "E"; + private const string StartingTag = "StartingTagDummy"; + private const string AddedTag = "AddedTagDummy"; + private const string UnusedTag = "UnusedTagDummy"; // Do not register this one private const string UnregisteredTag = "AAAAAAAAA"; - private static readonly string Prototypes = $@" + [TestPrototypes] + private const string Prototypes = $@" - type: Tag id: {StartingTag} @@ -45,8 +46,7 @@ namespace Content.IntegrationTests.Tests.Tag { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; diff --git a/Content.IntegrationTests/Tests/Utility/EntitySystemExtensionsTest.cs b/Content.IntegrationTests/Tests/Utility/EntitySystemExtensionsTest.cs index e946cd15b4..d5df5758d0 100644 --- a/Content.IntegrationTests/Tests/Utility/EntitySystemExtensionsTest.cs +++ b/Content.IntegrationTests/Tests/Utility/EntitySystemExtensionsTest.cs @@ -12,7 +12,8 @@ namespace Content.IntegrationTests.Tests.Utility { private const string BlockerDummyId = "BlockerDummy"; - private static readonly string Prototypes = $@" + [TestPrototypes] + private const string Prototypes = $@" - type: entity id: {BlockerDummyId} name: {BlockerDummyId} @@ -33,8 +34,7 @@ namespace Content.IntegrationTests.Tests.Utility { await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { - NoClient = true, - ExtraPrototypes = Prototypes + NoClient = true }); var server = pairTracker.Pair.Server; diff --git a/Content.IntegrationTests/Tests/Utility/EntityWhitelistTest.cs b/Content.IntegrationTests/Tests/Utility/EntityWhitelistTest.cs index 92d0359e5a..c0c81b1ecb 100644 --- a/Content.IntegrationTests/Tests/Utility/EntityWhitelistTest.cs +++ b/Content.IntegrationTests/Tests/Utility/EntityWhitelistTest.cs @@ -12,11 +12,12 @@ namespace Content.IntegrationTests.Tests.Utility private const string InvalidComponent = "Sprite"; private const string ValidComponent = "Physics"; - private static readonly string Prototypes = $@" + [TestPrototypes] + private const string Prototypes = $@" - type: Tag - id: ValidTag + id: WhitelistTestValidTag - type: Tag - id: InvalidTag + id: WhitelistTestInvalidTag - type: entity id: WhitelistDummy @@ -30,34 +31,34 @@ namespace Content.IntegrationTests.Tests.Utility components: - {ValidComponent} tags: - - ValidTag + - WhitelistTestValidTag - type: entity id: InvalidComponentDummy components: - type: {InvalidComponent} - type: entity - id: InvalidTagDummy + id: WhitelistTestInvalidTagDummy components: - type: Tag tags: - - InvalidTag + - WhitelistTestInvalidTag - type: entity id: ValidComponentDummy components: - type: {ValidComponent} - type: entity - id: ValidTagDummy + id: WhitelistTestValidTagDummy components: - type: Tag tags: - - ValidTag"; + - WhitelistTestValidTag"; [Test] public async Task Test() { - await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true, ExtraPrototypes = Prototypes }); + await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true }); var server = pairTracker.Pair.Server; var testMap = await PoolManager.CreateTestMap(pairTracker); @@ -68,16 +69,16 @@ namespace Content.IntegrationTests.Tests.Utility await server.WaitAssertion(() => { var validComponent = sEntities.SpawnEntity("ValidComponentDummy", mapCoordinates); - var validTag = sEntities.SpawnEntity("ValidTagDummy", mapCoordinates); + var WhitelistTestValidTag = sEntities.SpawnEntity("WhitelistTestValidTagDummy", mapCoordinates); var invalidComponent = sEntities.SpawnEntity("InvalidComponentDummy", mapCoordinates); - var invalidTag = sEntities.SpawnEntity("InvalidTagDummy", mapCoordinates); + var WhitelistTestInvalidTag = sEntities.SpawnEntity("WhitelistTestInvalidTagDummy", mapCoordinates); // Test instantiated on its own var whitelistInst = new EntityWhitelist { Components = new[] { $"{ValidComponent}" }, - Tags = new() { "ValidTag" } + Tags = new() { "WhitelistTestValidTag" } }; whitelistInst.UpdateRegistrations(); Assert.That(whitelistInst, Is.Not.Null); @@ -91,10 +92,10 @@ namespace Content.IntegrationTests.Tests.Utility Assert.Multiple(() => { Assert.That(whitelistInst.IsValid(validComponent), Is.True); - Assert.That(whitelistInst.IsValid(validTag), Is.True); + Assert.That(whitelistInst.IsValid(WhitelistTestValidTag), Is.True); Assert.That(whitelistInst.IsValid(invalidComponent), Is.False); - Assert.That(whitelistInst.IsValid(invalidTag), Is.False); + Assert.That(whitelistInst.IsValid(WhitelistTestInvalidTag), Is.False); }); // Test from serialized @@ -111,10 +112,10 @@ namespace Content.IntegrationTests.Tests.Utility Assert.Multiple(() => { Assert.That(whitelistSer.IsValid(validComponent), Is.True); - Assert.That(whitelistSer.IsValid(validTag), Is.True); + Assert.That(whitelistSer.IsValid(WhitelistTestValidTag), Is.True); Assert.That(whitelistSer.IsValid(invalidComponent), Is.False); - Assert.That(whitelistSer.IsValid(invalidTag), Is.False); + Assert.That(whitelistSer.IsValid(WhitelistTestInvalidTag), Is.False); }); }); await pairTracker.CleanReturnAsync(); diff --git a/Content.IntegrationTests/Tests/VendingMachineRestockTest.cs b/Content.IntegrationTests/Tests/VendingMachineRestockTest.cs index db9e4ddf37..5ef3f1b660 100644 --- a/Content.IntegrationTests/Tests/VendingMachineRestockTest.cs +++ b/Content.IntegrationTests/Tests/VendingMachineRestockTest.cs @@ -11,6 +11,7 @@ using Content.Shared.Damage.Prototypes; using Content.Shared.VendingMachines; using Content.Shared.Wires; using Content.Server.Wires; +using Content.Shared.Prototypes; namespace Content.IntegrationTests.Tests { @@ -19,10 +20,11 @@ namespace Content.IntegrationTests.Tests [TestOf(typeof(VendingMachineSystem))] public sealed class VendingMachineRestockTest : EntitySystem { + [TestPrototypes] private const string Prototypes = @" - type: entity - name: HumanDummy - id: HumanDummy + name: HumanVendingDummy + id: HumanVendingDummy components: - type: Hands - type: Body @@ -117,8 +119,9 @@ namespace Content.IntegrationTests.Tests // Collect all the prototypes with restock components. foreach (var proto in prototypeManager.EnumeratePrototypes()) { - if (proto.Abstract || - !proto.TryGetComponent(out var restock)) + if (proto.Abstract + || pairTracker.Pair.IsTestPrototype(proto) + || !proto.HasComponent()) { continue; } @@ -173,7 +176,7 @@ namespace Content.IntegrationTests.Tests [Test] public async Task TestCompleteRestockProcess() { - await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true, ExtraPrototypes = Prototypes }); + await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true }); var server = pairTracker.Pair.Server; await server.WaitIdleAsync(); @@ -197,7 +200,7 @@ namespace Content.IntegrationTests.Tests var coordinates = testMap.GridCoords; // Spawn the entities. - user = entityManager.SpawnEntity("HumanDummy", coordinates); + user = entityManager.SpawnEntity("HumanVendingDummy", coordinates); machine = entityManager.SpawnEntity("VendingMachineTest", coordinates); packageRight = entityManager.SpawnEntity("TestRestockCorrect", coordinates); packageWrong = entityManager.SpawnEntity("TestRestockWrong", coordinates); @@ -259,7 +262,7 @@ namespace Content.IntegrationTests.Tests [Test] public async Task TestRestockBreaksOpen() { - await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true, ExtraPrototypes = Prototypes }); + await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true }); var server = pairTracker.Pair.Server; await server.WaitIdleAsync(); @@ -323,7 +326,7 @@ namespace Content.IntegrationTests.Tests [Test] public async Task TestRestockInventoryBounds() { - await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true, ExtraPrototypes = Prototypes }); + await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true }); var server = pairTracker.Pair.Server; await server.WaitIdleAsync(); diff --git a/Content.MapRenderer/Program.cs b/Content.MapRenderer/Program.cs index ccd8f04757..766ee3ac68 100644 --- a/Content.MapRenderer/Program.cs +++ b/Content.MapRenderer/Program.cs @@ -29,6 +29,7 @@ namespace Content.MapRenderer if (!CommandLineArguments.TryParse(args, out var arguments)) return; + PoolManager.Startup(null); if (arguments.Maps.Count == 0) { Console.WriteLine("Didn't specify any maps to paint! Loading the map list..."); @@ -135,6 +136,7 @@ namespace Content.MapRenderer } await Run(arguments); + PoolManager.Shutdown(); } private static async Task Run(CommandLineArguments arguments) diff --git a/Content.YAMLLinter/Program.cs b/Content.YAMLLinter/Program.cs index a10ad7d75c..4ea31e9311 100644 --- a/Content.YAMLLinter/Program.cs +++ b/Content.YAMLLinter/Program.cs @@ -15,6 +15,7 @@ namespace Content.YAMLLinter { private static async Task Main(string[] _) { + PoolManager.Startup(null); var stopwatch = new Stopwatch(); stopwatch.Start(); @@ -42,6 +43,7 @@ namespace Content.YAMLLinter } Console.WriteLine($"{count} errors found in {(int) stopwatch.Elapsed.TotalMilliseconds} ms."); + PoolManager.Shutdown(); return -1; }