#nullable enable using Robust.Shared.Random; namespace Content.IntegrationTests; /// /// Settings for the pooled server, and client pair. /// Some options are for changing the pair, and others are /// so the pool can properly clean up what you borrowed. /// public sealed class PoolSettings { /// /// Set to true if the test will ruin the server/client pair. /// public bool Destructive { get; init; } /// /// Set to true if the given server/client pair should be created fresh. /// public bool Fresh { get; init; } /// /// Set to true if the given server should be using a dummy ticker. Ignored if is true. /// public bool DummyTicker { get; init; } = true; /// /// If true, this enables the creation of admin logs during the test. /// public bool AdminLogsEnabled { get; init; } /// /// Set to true if the given server/client pair should be connected from each other. /// Defaults to disconnected as it makes dirty recycling slightly faster. /// If is true, this option is ignored. /// public bool Connected { get; init; } /// /// Set to true if the given server/client pair should be in the lobby. /// If the pair is not in the lobby at the end of the test, this test must be marked as dirty. /// /// /// If this is enabled, the value of is ignored. /// public bool InLobby { get; init; } /// /// Set this to true to skip loading the content files. /// Note: This setting won't work with a client. /// public bool NoLoadContent { get; init; } /// /// 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 bool NoLoadTestPrototypes { get; init; } /// /// Set this to true to disable the NetInterp CVar on the given server/client pair /// public bool DisableInterpolate { get; init; } /// /// Set this to true to always clean up the server/client pair before giving it to another borrower /// public bool Dirty { get; init; } /// /// Set this to the path of a map to have the given server/client pair load the map. /// public string Map { get; init; } = PoolManager.TestMap; /// /// Overrides the test name detection, and uses this in the test history instead /// public string? TestName { get; set; } /// /// If set, this will be used to call /// public int? ServerSeed { get; set; } /// /// If set, this will be used to call /// public int? ClientSeed { get; set; } #region Inferred Properties /// /// If the returned pair must not be reused /// public bool MustNotBeReused => Destructive || NoLoadContent || NoLoadTestPrototypes; /// /// If the given pair must be brand new /// public bool MustBeNew => Fresh || NoLoadContent || NoLoadTestPrototypes; public bool UseDummyTicker => !InLobby && DummyTicker; public bool ShouldBeConnected => InLobby || Connected; #endregion /// /// Tries to guess if we can skip recycling the server/client pair. /// /// The next set of settings the old pair will be set to /// If we can skip cleaning it up public bool CanFastRecycle(PoolSettings nextSettings) { if (MustNotBeReused) throw new InvalidOperationException("Attempting to recycle a non-reusable test."); if (nextSettings.MustBeNew) throw new InvalidOperationException("Attempting to recycle a test while requesting a fresh test."); if (Dirty) return false; // Check that certain settings match. return !ShouldBeConnected == !nextSettings.ShouldBeConnected && UseDummyTicker == nextSettings.UseDummyTicker && Map == nextSettings.Map && InLobby == nextSettings.InLobby; } }