| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- #nullable enable
- using Robust.Shared.Random;
- namespace Content.IntegrationTests;
- /// <summary>
- /// 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.
- /// </summary>
- public sealed class PoolSettings
- {
- /// <summary>
- /// Set to true if the test will ruin the server/client pair.
- /// </summary>
- public bool Destructive { get; init; }
- /// <summary>
- /// Set to true if the given server/client pair should be created fresh.
- /// </summary>
- public bool Fresh { get; init; }
- /// <summary>
- /// Set to true if the given server should be using a dummy ticker. Ignored if <see cref="InLobby"/> is true.
- /// </summary>
- public bool DummyTicker { get; init; } = true;
- /// <summary>
- /// If true, this enables the creation of admin logs during the test.
- /// </summary>
- public bool AdminLogsEnabled { get; init; }
- /// <summary>
- /// 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 <see cref="InLobby"/> is true, this option is ignored.
- /// </summary>
- public bool Connected { get; init; }
- /// <summary>
- /// 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.
- /// </summary>
- /// <remarks>
- /// If this is enabled, the value of <see cref="DummyTicker"/> is ignored.
- /// </remarks>
- public bool InLobby { get; init; }
- /// <summary>
- /// Set this to true to skip loading the content files.
- /// Note: This setting won't work with a client.
- /// </summary>
- public bool NoLoadContent { get; init; }
- /// <summary>
- /// 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 <see cref="Pair.TestPair.IsTestPrototype(Robust.Shared.Prototypes.EntityPrototype)"/> if you need to exclude test prototypees.
- /// </summary>
- public bool NoLoadTestPrototypes { get; init; }
- /// <summary>
- /// Set this to true to disable the NetInterp CVar on the given server/client pair
- /// </summary>
- public bool DisableInterpolate { get; init; }
- /// <summary>
- /// Set this to true to always clean up the server/client pair before giving it to another borrower
- /// </summary>
- public bool Dirty { get; init; }
- /// <summary>
- /// Set this to the path of a map to have the given server/client pair load the map.
- /// </summary>
- public string Map { get; init; } = PoolManager.TestMap;
- /// <summary>
- /// Overrides the test name detection, and uses this in the test history instead
- /// </summary>
- public string? TestName { get; set; }
- /// <summary>
- /// If set, this will be used to call <see cref="IRobustRandom.SetSeed"/>
- /// </summary>
- public int? ServerSeed { get; set; }
- /// <summary>
- /// If set, this will be used to call <see cref="IRobustRandom.SetSeed"/>
- /// </summary>
- public int? ClientSeed { get; set; }
- #region Inferred Properties
- /// <summary>
- /// If the returned pair must not be reused
- /// </summary>
- public bool MustNotBeReused => Destructive || NoLoadContent || NoLoadTestPrototypes;
- /// <summary>
- /// If the given pair must be brand new
- /// </summary>
- public bool MustBeNew => Fresh || NoLoadContent || NoLoadTestPrototypes;
- public bool UseDummyTicker => !InLobby && DummyTicker;
- public bool ShouldBeConnected => InLobby || Connected;
- #endregion
- /// <summary>
- /// Tries to guess if we can skip recycling the server/client pair.
- /// </summary>
- /// <param name="nextSettings">The next set of settings the old pair will be set to</param>
- /// <returns>If we can skip cleaning it up</returns>
- 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;
- }
- }
|