Skip to content

Commit

Permalink
Fix content.integration tests warnings (#17817)
Browse files Browse the repository at this point in the history
Co-authored-by: metalgearsloth <[email protected]>
  • Loading branch information
TemporalOroboros and metalgearsloth authored Jul 6, 2023
1 parent 20c1754 commit ba91023
Show file tree
Hide file tree
Showing 121 changed files with 3,675 additions and 1,978 deletions.
1 change: 1 addition & 0 deletions Content.IntegrationTests/Content.IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
<ProjectReference Include="..\RobustToolbox\Robust.UnitTesting\Robust.UnitTesting.csproj" />
</ItemGroup>
<Import Project="..\RobustToolbox\MSBuild\Robust.Properties.targets" />
<Import Project="..\RobustToolbox\MSBuild\Robust.CompNetworkGenerator.targets" />
</Project>
2 changes: 0 additions & 2 deletions Content.IntegrationTests/DummyParallaxManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;
using System.Threading.Tasks;
using Content.Client.Parallax.Managers;
using Content.Client.Parallax;
using Robust.Shared.Maths;
Expand Down
5 changes: 5 additions & 0 deletions Content.IntegrationTests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Global usings for Content.IntegrationTests

global using NUnit.Framework;
global using System;
global using System.Threading.Tasks;
97 changes: 54 additions & 43 deletions Content.IntegrationTests/PoolManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Content.Client.IoC;
using Content.Client.Parallax.Managers;
using Content.IntegrationTests.Tests;
Expand All @@ -14,8 +12,6 @@
using Content.IntegrationTests.Tests.Networking;
using Content.Server.GameTicking;
using Content.Shared.CCVar;
using Microsoft.Diagnostics.Tracing.Parsers.Kernel;
using NUnit.Framework;
using Robust.Client;
using Robust.Server;
using Robust.Shared;
Expand Down Expand Up @@ -61,13 +57,13 @@ private static readonly (string cvar, string value)[] ServerTestCvars =
// @formatter:on
};

private static int PairId;
private static object PairLock = new();
private static int _pairId;
private static readonly object PairLock = new();

// Pair, IsBorrowed
private static Dictionary<Pair, bool> Pairs = new();
private static bool Dead;
private static Exception PoolFailureReason;
private static readonly Dictionary<Pair, bool> Pairs = new();
private static bool _dead;
private static Exception _poolFailureReason;

private static async Task ConfigurePrototypes(RobustIntegrationTest.IntegrationInstance instance,
PoolSettings settings)
Expand Down Expand Up @@ -108,18 +104,21 @@ await instance.WaitPost(() =>

options.BeforeStart += () =>
{
IoCManager.Resolve<IEntitySystemManager>()
.LoadExtraSystemType<SimplePredictReconcileTest.PredictionTestEntitySystem>();
IoCManager.Resolve<IComponentFactory>().RegisterClass<SimplePredictReconcileTest.PredictionTestComponent>();
var entSysMan = IoCManager.Resolve<IEntitySystemManager>();
var compFactory = IoCManager.Resolve<IComponentFactory>();
entSysMan.LoadExtraSystemType<AutoPredictReconcileTest.AutoPredictionTestEntitySystem>();
compFactory.RegisterClass<AutoPredictionTestComponent>();
entSysMan.LoadExtraSystemType<SimplePredictReconcileTest.PredictionTestEntitySystem>();
compFactory.RegisterClass<SimplePredictReconcileTest.PredictionTestComponent>();
entSysMan.LoadExtraSystemType<SystemPredictReconcileTest.SystemPredictionTestEntitySystem>();
compFactory.RegisterClass<SystemPredictReconcileTest.SystemPredictionTestComponent>();
IoCManager.Register<ResettingEntitySystemTests.TestRoundRestartCleanupEvent>();
IoCManager.Register<InteractionSystemTests.TestInteractionSystem>();
IoCManager.Register<DeviceNetworkTestSystem>();
IoCManager.Resolve<IEntitySystemManager>()
.LoadExtraSystemType<ResettingEntitySystemTests.TestRoundRestartCleanupEvent>();
IoCManager.Resolve<IEntitySystemManager>()
.LoadExtraSystemType<InteractionSystemTests.TestInteractionSystem>();
IoCManager.Resolve<IEntitySystemManager>().LoadExtraSystemType<DeviceNetworkTestSystem>();
IoCManager.Resolve<IEntitySystemManager>().LoadExtraSystemType<TestDestructibleListenerSystem>();
entSysMan.LoadExtraSystemType<ResettingEntitySystemTests.TestRoundRestartCleanupEvent>();
entSysMan.LoadExtraSystemType<InteractionSystemTests.TestInteractionSystem>();
entSysMan.LoadExtraSystemType<DeviceNetworkTestSystem>();
entSysMan.LoadExtraSystemType<TestDestructibleListenerSystem>();
IoCManager.Resolve<ILogManager>().GetSawmill("loc").Level = LogLevel.Error;
IoCManager.Resolve<IConfigurationManager>()
.OnValueChanged(RTCVars.FailureLogLevel, value => logHandler.FailureLevel = value, true);
Expand All @@ -141,9 +140,9 @@ public static void Shutdown()
List<Pair> localPairs;
lock (PairLock)
{
if(Dead)
if (_dead)
return;
Dead = true;
_dead = true;
localPairs = Pairs.Keys.ToList();
}

Expand All @@ -163,7 +162,7 @@ public static string DeathReport()
{
var borrowed = Pairs[pair];
builder.AppendLine($"Pair {pair.PairId}, Tests Run: {pair.TestHistory.Count}, Borrowed: {borrowed}");
for (int i = 0; i < pair.TestHistory.Count; i++)
for (var i = 0; i < pair.TestHistory.Count; i++)
{
builder.AppendLine($"#{i}: {pair.TestHistory[i]}");
}
Expand Down Expand Up @@ -211,10 +210,14 @@ public static string DeathReport()
{
ClientBeforeIoC = () =>
{
IoCManager.Resolve<IEntitySystemManager>()
.LoadExtraSystemType<SimplePredictReconcileTest.PredictionTestEntitySystem>();
IoCManager.Resolve<IComponentFactory>()
.RegisterClass<SimplePredictReconcileTest.PredictionTestComponent>();
var entSysMan = IoCManager.Resolve<IEntitySystemManager>();
var compFactory = IoCManager.Resolve<IComponentFactory>();
entSysMan.LoadExtraSystemType<AutoPredictReconcileTest.AutoPredictionTestEntitySystem>();
compFactory.RegisterClass<AutoPredictionTestComponent>();
entSysMan.LoadExtraSystemType<SimplePredictReconcileTest.PredictionTestEntitySystem>();
compFactory.RegisterClass<SimplePredictReconcileTest.PredictionTestComponent>();
entSysMan.LoadExtraSystemType<SystemPredictReconcileTest.SystemPredictionTestEntitySystem>();
compFactory.RegisterClass<SystemPredictReconcileTest.SystemPredictionTestComponent>();
IoCManager.Register<IParallaxManager, DummyParallaxManager>(true);
IoCManager.Resolve<ILogManager>().GetSawmill("loc").Level = LogLevel.Error;
IoCManager.Resolve<IConfigurationManager>()
Expand All @@ -232,9 +235,9 @@ public static string DeathReport()

private static void SetupCVars(PoolSettings poolSettings, RobustIntegrationTest.IntegrationOptions options)
{
foreach (var serverTestCvar in ServerTestCvars)
foreach (var (cvar, value) in ServerTestCvars)
{
options.CVarOverrides[serverTestCvar.cvar] = serverTestCvar.value;
options.CVarOverrides[cvar] = value;
}

if (poolSettings.DummyTicker)
Expand Down Expand Up @@ -266,8 +269,10 @@ private static void SetupCVars(PoolSettings poolSettings, RobustIntegrationTest.
/// </summary>
/// <param name="poolSettings">See <see cref="PoolSettings"/></param>
/// <returns></returns>
public static async Task<PairTracker> GetServerClient(PoolSettings poolSettings = null) =>
await GetServerClientPair(poolSettings ?? new PoolSettings());
public static async Task<PairTracker> GetServerClient(PoolSettings poolSettings = null)
{
return await GetServerClientPair(poolSettings ?? new PoolSettings());
}

private static string GetDefaultTestName(TestContext testContext)
{
Expand Down Expand Up @@ -328,7 +333,7 @@ await testOut.WriteLineAsync(
if (pair != null && pair.TestHistory.Count > 1)
{
await testOut.WriteLineAsync($"{nameof(GetServerClientPair)}: Pair {pair.PairId} Test History Start");
for (int i = 0; i < pair.TestHistory.Count; i++)
for (var i = 0; i < pair.TestHistory.Count; i++)
{
await testOut.WriteLineAsync($"- Pair {pair.PairId} Test #{i}: {pair.TestHistory[i]}");
}
Expand Down Expand Up @@ -403,6 +408,8 @@ private static async Task CleanPooledPair(PoolSettings poolSettings, Pair pair,
methodWatch.Start();
await testOut.WriteLineAsync($"Recycling: {methodWatch.Elapsed.TotalMilliseconds} ms: Setting CVar ");
var configManager = pair.Server.ResolveDependency<IConfigurationManager>();
var entityManager = pair.Server.ResolveDependency<IEntityManager>();
var gameTicker = entityManager.System<GameTicker>();
await pair.Server.WaitPost(() =>
{
configManager.SetCVar(CCVars.GameLobbyEnabled, poolSettings.InLobby);
Expand All @@ -414,14 +421,14 @@ await pair.Server.WaitPost(() =>
pair.Client.SetConnectTarget(pair.Server);
await pair.Server.WaitPost(() =>
{
EntitySystem.Get<GameTicker>().RestartRound();
gameTicker.RestartRound();
});
await pair.Client.WaitPost(() =>
{
cNetMgr.ClientConnect(null!, 0, null!);
});
}
await ReallyBeIdle(pair,11);
await ReallyBeIdle(pair, 11);

await testOut.WriteLineAsync($"Recycling: {methodWatch.Elapsed.TotalMilliseconds} ms: Disconnecting client, and restarting server");

Expand All @@ -443,7 +450,7 @@ await pair.Server.WaitPost(() =>
serverProtoManager.RemoveString(pair.Settings.ExtraPrototypes.Trim());
});
}
if(!pair.Settings.NoClient)
if (!pair.Settings.NoClient)
{
var clientProtoManager = pair.Client.ResolveDependency<IPrototypeManager>();
await pair.Client.WaitPost(() =>
Expand Down Expand Up @@ -471,7 +478,7 @@ await pair.Client.WaitPost(() =>
await testOut.WriteLineAsync($"Recycling: {methodWatch.Elapsed.TotalMilliseconds} ms: Restarting server again");
await pair.Server.WaitPost(() =>
{
EntitySystem.Get<GameTicker>().RestartRound();
gameTicker.RestartRound();
});


Expand All @@ -495,17 +502,17 @@ await pair.Client.WaitPost(() =>

private static void DieIfPoolFailure()
{
if (PoolFailureReason != null)
if (_poolFailureReason != null)
{
// If the PoolFailureReason is not null, we can assume at least one test failed.
// If the _poolFailureReason is not null, we can assume at least one test failed.
// So we say inconclusive so we don't add more failed tests to search through.
Assert.Inconclusive(@"
In a different test, the pool manager had an exception when trying to create a server/client pair.
Instead of risking that the pool manager will fail at creating a server/client pairs for every single test,
we are just going to end this here to save a lot of time. This is the exception that started this:\n {0}", PoolFailureReason);
we are just going to end this here to save a lot of time. This is the exception that started this:\n {0}", _poolFailureReason);
}

if (Dead)
if (_dead)
{
// If Pairs is null, we ran out of time, we can't assume a test failed.
// So we are going to tell it all future tests are a failure.
Expand All @@ -525,12 +532,12 @@ private static async Task<Pair> CreateServerClientPair(PoolSettings poolSettings
ServerLogHandler = serverLog,
Client = client,
ClientLogHandler = clientLog,
PairId = Interlocked.Increment(ref PairId)
PairId = Interlocked.Increment(ref _pairId)
};
}
catch (Exception ex)
{
PoolFailureReason = ex;
_poolFailureReason = ex;
throw;
}

Expand Down Expand Up @@ -565,6 +572,8 @@ public static async Task<TestMapData> CreateTestMap(PairTracker pairTracker)
var settings = pairTracker.Pair.Settings;
var mapManager = server.ResolveDependency<IMapManager>();
var tileDefinitionManager = server.ResolveDependency<ITileDefinitionManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
var xformSystem = entityManager.System<SharedTransformSystem>();

if (settings.NoServer) throw new Exception("Cannot setup test map without server");
var mapData = new TestMapData();
Expand All @@ -573,7 +582,7 @@ await server.WaitPost(() =>
mapData.MapId = mapManager.CreateMap();
mapData.MapUid = mapManager.GetMapEntityId(mapData.MapId);
mapData.MapGrid = mapManager.CreateGrid(mapData.MapId);
mapData.GridUid = mapData.MapGrid.Owner;
mapData.GridUid = mapData.MapGrid.Owner; // Fixing this requires an engine PR.
mapData.GridCoords = new EntityCoordinates(mapData.GridUid, 0, 0);
var plating = tileDefinitionManager["Plating"];
var platingTile = new Tile(plating.TileId);
Expand Down Expand Up @@ -610,11 +619,11 @@ public static async Task RunTicksSync(Pair pair, int ticks)
/// <param name="runTicks">How many ticks to run</param>
public static async Task ReallyBeIdle(Pair pair, int runTicks = 25)
{
for (int i = 0; i < runTicks; i++)
for (var i = 0; i < runTicks; i++)
{
await pair.Client.WaitRunTicks(1);
await pair.Server.WaitRunTicks(1);
for (int idleCycles = 0; idleCycles < 4; idleCycles++)
for (var idleCycles = 0; idleCycles < 4; idleCycles++)
{
await pair.Client.WaitIdleAsync();
await pair.Server.WaitIdleAsync();
Expand Down Expand Up @@ -809,7 +818,9 @@ public bool CanFastRecycle(PoolSettings nextSettings)
// 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
Expand Down
5 changes: 1 addition & 4 deletions Content.IntegrationTests/PoolManagerTestEventHandler.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Threading.Tasks;
using NUnit.Framework;


[assembly: Parallelizable(ParallelScope.Children)]

namespace Content.IntegrationTests;
Expand Down
4 changes: 1 addition & 3 deletions Content.IntegrationTests/PoolTestLogHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.IO;
using NUnit.Framework;
using System.IO;
using Robust.Shared.Log;
using Robust.Shared.Timing;
using Serilog.Events;
Expand Down
Loading

0 comments on commit ba91023

Please sign in to comment.