Fix content.integration tests warnings (#17817)

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
TemporalOroboros
2023-07-05 21:54:25 -07:00
committed by GitHub
parent 20c1754abd
commit ba91023a85
121 changed files with 3658 additions and 1961 deletions

View File

@@ -1,6 +1,4 @@
#nullable enable
using System;
using System.Threading.Tasks;
using Content.Server.NodeContainer;
using Content.Server.NodeContainer.EntitySystems;
using Content.Server.NodeContainer.Nodes;
@@ -8,13 +6,10 @@ using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Power.Nodes;
using Content.Shared.Coordinates;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Timing;
using TerraFX.Interop.Windows;
using static Content.Server.Power.Pow3r.PowerState;
namespace Content.IntegrationTests.Tests.Power
{
@@ -166,7 +161,11 @@ namespace Content.IntegrationTests.Tests.Power
[Test]
public async Task TestSimpleSurplus()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, ExtraPrototypes = Prototypes});
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
{
NoClient = true,
ExtraPrototypes = Prototypes
});
var server = pairTracker.Pair.Server;
var mapManager = server.ResolveDependency<IMapManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
@@ -206,12 +205,15 @@ namespace Content.IntegrationTests.Tests.Power
await server.WaitAssertion(() =>
{
// Assert both consumers fully powered
Assert.That(consumer1.ReceivedPower, Is.EqualTo(consumer1.DrawRate).Within(0.1));
Assert.That(consumer2.ReceivedPower, Is.EqualTo(consumer2.DrawRate).Within(0.1));
Assert.Multiple(() =>
{
// Assert both consumers fully powered
Assert.That(consumer1.ReceivedPower, Is.EqualTo(consumer1.DrawRate).Within(0.1));
Assert.That(consumer2.ReceivedPower, Is.EqualTo(consumer2.DrawRate).Within(0.1));
// Assert that load adds up on supply.
Assert.That(supplier.CurrentSupply, Is.EqualTo(loadPower * 2).Within(0.1));
// Assert that load adds up on supply.
Assert.That(supplier.CurrentSupply, Is.EqualTo(loadPower * 2).Within(0.1));
});
});
await pairTracker.CleanReturnAsync();
@@ -224,7 +226,11 @@ namespace Content.IntegrationTests.Tests.Power
[Test]
public async Task TestSimpleDeficit()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, ExtraPrototypes = Prototypes});
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
{
NoClient = true,
ExtraPrototypes = Prototypes
});
var server = pairTracker.Pair.Server;
var mapManager = server.ResolveDependency<IMapManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
@@ -264,12 +270,15 @@ namespace Content.IntegrationTests.Tests.Power
await server.WaitAssertion(() =>
{
// Assert both consumers get 33% power.
Assert.That(consumer1.ReceivedPower, Is.EqualTo(consumer1.DrawRate / 3).Within(0.1));
Assert.That(consumer2.ReceivedPower, Is.EqualTo(consumer2.DrawRate / 3).Within(0.1));
Assert.Multiple(() =>
{
// Assert both consumers get 33% power.
Assert.That(consumer1.ReceivedPower, Is.EqualTo(consumer1.DrawRate / 3).Within(0.1));
Assert.That(consumer2.ReceivedPower, Is.EqualTo(consumer2.DrawRate / 3).Within(0.1));
// Supply should be maxed out
Assert.That(supplier.CurrentSupply, Is.EqualTo(supplier.MaxSupply).Within(0.1));
// Supply should be maxed out
Assert.That(supplier.CurrentSupply, Is.EqualTo(supplier.MaxSupply).Within(0.1));
});
});
await pairTracker.CleanReturnAsync();
@@ -278,7 +287,11 @@ namespace Content.IntegrationTests.Tests.Power
[Test]
public async Task TestSupplyRamp()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, ExtraPrototypes = Prototypes});
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
{
NoClient = true,
ExtraPrototypes = Prototypes
});
var server = pairTracker.Pair.Server;
var mapManager = server.ResolveDependency<IMapManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
@@ -319,9 +332,12 @@ namespace Content.IntegrationTests.Tests.Power
await server.WaitAssertion(() =>
{
// First tick, supply should be delivering 100 W (max tolerance) and start ramping up.
Assert.That(supplier.CurrentSupply, Is.EqualTo(100).Within(0.1));
Assert.That(consumer.ReceivedPower, Is.EqualTo(100).Within(0.1));
Assert.Multiple(() =>
{
// First tick, supply should be delivering 100 W (max tolerance) and start ramping up.
Assert.That(supplier.CurrentSupply, Is.EqualTo(100).Within(0.1));
Assert.That(consumer.ReceivedPower, Is.EqualTo(100).Within(0.1));
});
});
// run for 0.25 seconds (minus the previous tick)
@@ -330,10 +346,13 @@ namespace Content.IntegrationTests.Tests.Power
await server.WaitAssertion(() =>
{
// After 15 ticks (0.25 seconds), supply ramp pos should be at 100 W and supply at 100, approx.
Assert.That(supplier.CurrentSupply, Is.EqualTo(200).Within(tickDev));
Assert.That(supplier.SupplyRampPosition, Is.EqualTo(100).Within(tickDev));
Assert.That(consumer.ReceivedPower, Is.EqualTo(200).Within(tickDev));
Assert.Multiple(() =>
{
// After 15 ticks (0.25 seconds), supply ramp pos should be at 100 W and supply at 100, approx.
Assert.That(supplier.CurrentSupply, Is.EqualTo(200).Within(tickDev));
Assert.That(supplier.SupplyRampPosition, Is.EqualTo(100).Within(tickDev));
Assert.That(consumer.ReceivedPower, Is.EqualTo(200).Within(tickDev));
});
});
@@ -344,10 +363,13 @@ namespace Content.IntegrationTests.Tests.Power
await server.WaitAssertion(() =>
{
// After 1 second total, ramp should be at 400 and supply should be at 400, everybody happy.
Assert.That(supplier.CurrentSupply, Is.EqualTo(400).Within(tickDev));
Assert.That(supplier.SupplyRampPosition, Is.EqualTo(400).Within(tickDev));
Assert.That(consumer.ReceivedPower, Is.EqualTo(400).Within(tickDev));
Assert.Multiple(() =>
{
// After 1 second total, ramp should be at 400 and supply should be at 400, everybody happy.
Assert.That(supplier.CurrentSupply, Is.EqualTo(400).Within(tickDev));
Assert.That(supplier.SupplyRampPosition, Is.EqualTo(400).Within(tickDev));
Assert.That(consumer.ReceivedPower, Is.EqualTo(400).Within(tickDev));
});
});
await pairTracker.CleanReturnAsync();
@@ -356,11 +378,16 @@ namespace Content.IntegrationTests.Tests.Power
[Test]
public async Task TestBatteryRamp()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, ExtraPrototypes = Prototypes});
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
{
NoClient = true,
ExtraPrototypes = Prototypes
});
var server = pairTracker.Pair.Server;
var mapManager = server.ResolveDependency<IMapManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
var gameTiming = server.ResolveDependency<IGameTiming>();
var batterySys = entityManager.System<BatterySystem>();
const float startingCharge = 100_000;
PowerNetworkBatteryComponent netBattery = default!;
@@ -386,8 +413,8 @@ namespace Content.IntegrationTests.Tests.Power
battery = entityManager.GetComponent<BatteryComponent>(generatorEnt);
consumer = entityManager.GetComponent<PowerConsumerComponent>(consumerEnt);
battery.MaxCharge = startingCharge;
battery.CurrentCharge = startingCharge;
batterySys.SetMaxCharge(generatorEnt, startingCharge, battery);
batterySys.SetCharge(generatorEnt, startingCharge, battery);
netBattery.MaxSupply = 400;
netBattery.SupplyRampRate = 400;
netBattery.SupplyRampTolerance = 100;
@@ -402,9 +429,12 @@ namespace Content.IntegrationTests.Tests.Power
await server.WaitAssertion(() =>
{
// First tick, supply should be delivering 100 W (max tolerance) and start ramping up.
Assert.That(netBattery.CurrentSupply, Is.EqualTo(100).Within(0.1));
Assert.That(consumer.ReceivedPower, Is.EqualTo(100).Within(0.1));
Assert.Multiple(() =>
{
// First tick, supply should be delivering 100 W (max tolerance) and start ramping up.
Assert.That(netBattery.CurrentSupply, Is.EqualTo(100).Within(0.1));
Assert.That(consumer.ReceivedPower, Is.EqualTo(100).Within(0.1));
});
});
// run for 0.25 seconds (minus the previous tick)
@@ -413,14 +443,17 @@ namespace Content.IntegrationTests.Tests.Power
await server.WaitAssertion(() =>
{
// After 15 ticks (0.25 seconds), supply ramp pos should be at 100 W and supply at 100, approx.
Assert.That(netBattery.CurrentSupply, Is.EqualTo(200).Within(tickDev));
Assert.That(netBattery.SupplyRampPosition, Is.EqualTo(100).Within(tickDev));
Assert.That(consumer.ReceivedPower, Is.EqualTo(200).Within(tickDev));
Assert.Multiple(() =>
{
// After 15 ticks (0.25 seconds), supply ramp pos should be at 100 W and supply at 100, approx.
Assert.That(netBattery.CurrentSupply, Is.EqualTo(200).Within(tickDev));
Assert.That(netBattery.SupplyRampPosition, Is.EqualTo(100).Within(tickDev));
Assert.That(consumer.ReceivedPower, Is.EqualTo(200).Within(tickDev));
// Trivial integral to calculate expected power spent.
const double spentExpected = (200 + 100) / 2.0 * 0.25;
Assert.That(battery.CurrentCharge, Is.EqualTo(startingCharge - spentExpected).Within(tickDev));
// Trivial integral to calculate expected power spent.
const double spentExpected = (200 + 100) / 2.0 * 0.25;
Assert.That(battery.CurrentCharge, Is.EqualTo(startingCharge - spentExpected).Within(tickDev));
});
});
// run for 0.75 seconds
@@ -429,14 +462,17 @@ namespace Content.IntegrationTests.Tests.Power
await server.WaitAssertion(() =>
{
// After 1 second total, ramp should be at 400 and supply should be at 400, everybody happy.
Assert.That(netBattery.CurrentSupply, Is.EqualTo(400).Within(tickDev));
Assert.That(netBattery.SupplyRampPosition, Is.EqualTo(400).Within(tickDev));
Assert.That(consumer.ReceivedPower, Is.EqualTo(400).Within(tickDev));
Assert.Multiple(() =>
{
// After 1 second total, ramp should be at 400 and supply should be at 400, everybody happy.
Assert.That(netBattery.CurrentSupply, Is.EqualTo(400).Within(tickDev));
Assert.That(netBattery.SupplyRampPosition, Is.EqualTo(400).Within(tickDev));
Assert.That(consumer.ReceivedPower, Is.EqualTo(400).Within(tickDev));
// Trivial integral to calculate expected power spent.
const double spentExpected = (400 + 100) / 2.0 * 0.75 + 400 * 0.25;
Assert.That(battery.CurrentCharge, Is.EqualTo(startingCharge - spentExpected).Within(tickDev));
// Trivial integral to calculate expected power spent.
const double spentExpected = (400 + 100) / 2.0 * 0.75 + 400 * 0.25;
Assert.That(battery.CurrentCharge, Is.EqualTo(startingCharge - spentExpected).Within(tickDev));
});
});
await pairTracker.CleanReturnAsync();
@@ -451,6 +487,7 @@ namespace Content.IntegrationTests.Tests.Power
var server = pairTracker.Pair.Server;
var mapManager = server.ResolveDependency<IMapManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
var batterySys = entityManager.System<BatterySystem>();
PowerSupplierComponent supplier = default!;
PowerNetworkBatteryComponent netBattery = default!;
BatteryComponent battery = default!;
@@ -474,7 +511,7 @@ namespace Content.IntegrationTests.Tests.Power
var generatorEnt = entityManager.SpawnEntity("GeneratorDummy", grid.ToCoordinates());
var consumerEnt = entityManager.SpawnEntity("ConsumerDummy", grid.ToCoordinates(0, 1));
var batteryEnt = entityManager.SpawnEntity("DischargingBatteryDummy", grid.ToCoordinates(0,2));
var batteryEnt = entityManager.SpawnEntity("DischargingBatteryDummy", grid.ToCoordinates(0, 2));
netBattery = entityManager.GetComponent<PowerNetworkBatteryComponent>(batteryEnt);
battery = entityManager.GetComponent<BatteryComponent>(batteryEnt);
supplier = entityManager.GetComponent<PowerSupplierComponent>(generatorEnt);
@@ -482,13 +519,13 @@ namespace Content.IntegrationTests.Tests.Power
consumer.DrawRate = draw;
supplier.MaxSupply = draw/2;
supplier.MaxSupply = draw / 2;
supplier.SupplyRampRate = rampRate;
supplier.SupplyRampTolerance = rampTol;
battery.MaxCharge = 100_000;
battery.CurrentCharge = 100_000;
netBattery.MaxSupply = draw/2;
batterySys.SetMaxCharge(batteryEnt, 100_000, battery);
batterySys.SetCharge(batteryEnt, 100_000, battery);
netBattery.MaxSupply = draw / 2;
netBattery.SupplyRampRate = rampRate;
netBattery.SupplyRampTolerance = rampTol;
});
@@ -497,20 +534,26 @@ namespace Content.IntegrationTests.Tests.Power
await server.WaitAssertion(() =>
{
Assert.That(supplier.CurrentSupply, Is.EqualTo(rampTol).Within(0.1));
Assert.That(netBattery.CurrentSupply, Is.EqualTo(rampTol).Within(0.1));
Assert.That(consumer.ReceivedPower, Is.EqualTo(rampTol*2).Within(0.1));
Assert.Multiple(() =>
{
Assert.That(supplier.CurrentSupply, Is.EqualTo(rampTol).Within(0.1));
Assert.That(netBattery.CurrentSupply, Is.EqualTo(rampTol).Within(0.1));
Assert.That(consumer.ReceivedPower, Is.EqualTo(rampTol * 2).Within(0.1));
});
});
server.RunTicks(60);
await server.WaitAssertion(() =>
{
Assert.That(supplier.CurrentSupply, Is.EqualTo(draw/2).Within(0.1));
Assert.That(supplier.SupplyRampPosition, Is.EqualTo(draw/2).Within(0.1));
Assert.That(netBattery.CurrentSupply, Is.EqualTo(draw / 2).Within(0.1));
Assert.That(netBattery.SupplyRampPosition, Is.EqualTo(draw / 2).Within(0.1));
Assert.That(consumer.ReceivedPower, Is.EqualTo(draw).Within(0.1));
Assert.Multiple(() =>
{
Assert.That(supplier.CurrentSupply, Is.EqualTo(draw / 2).Within(0.1));
Assert.That(supplier.SupplyRampPosition, Is.EqualTo(draw / 2).Within(0.1));
Assert.That(netBattery.CurrentSupply, Is.EqualTo(draw / 2).Within(0.1));
Assert.That(netBattery.SupplyRampPosition, Is.EqualTo(draw / 2).Within(0.1));
Assert.That(consumer.ReceivedPower, Is.EqualTo(draw).Within(0.1));
});
});
// now we disconnect the load;
@@ -520,11 +563,14 @@ namespace Content.IntegrationTests.Tests.Power
await server.WaitAssertion(() =>
{
Assert.That(supplier.CurrentSupply, Is.EqualTo(0).Within(0.1));
Assert.That(supplier.SupplyRampPosition, Is.EqualTo(0).Within(0.1));
Assert.That(netBattery.CurrentSupply, Is.EqualTo(0).Within(0.1));
Assert.That(netBattery.SupplyRampPosition, Is.EqualTo(0).Within(0.1));
Assert.That(consumer.ReceivedPower, Is.EqualTo(0).Within(0.1));
Assert.Multiple(() =>
{
Assert.That(supplier.CurrentSupply, Is.EqualTo(0).Within(0.1));
Assert.That(supplier.SupplyRampPosition, Is.EqualTo(0).Within(0.1));
Assert.That(netBattery.CurrentSupply, Is.EqualTo(0).Within(0.1));
Assert.That(netBattery.SupplyRampPosition, Is.EqualTo(0).Within(0.1));
Assert.That(consumer.ReceivedPower, Is.EqualTo(0).Within(0.1));
});
});
await pairTracker.CleanReturnAsync();
@@ -533,11 +579,16 @@ namespace Content.IntegrationTests.Tests.Power
[Test]
public async Task TestSimpleBatteryChargeDeficit()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, ExtraPrototypes = Prototypes});
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
{
NoClient = true,
ExtraPrototypes = Prototypes
});
var server = pairTracker.Pair.Server;
var mapManager = server.ResolveDependency<IMapManager>();
var gameTiming = server.ResolveDependency<IGameTiming>();
var entityManager = server.ResolveDependency<IEntityManager>();
var batterySys = entityManager.System<BatterySystem>();
PowerSupplierComponent supplier = default!;
BatteryComponent battery = default!;
@@ -562,8 +613,8 @@ namespace Content.IntegrationTests.Tests.Power
supplier.MaxSupply = 500;
supplier.SupplyRampTolerance = 500;
battery.MaxCharge = 100000;
netBattery.MaxChargeRate = 1000;
batterySys.SetMaxCharge(batteryEnt, 100_000, battery);
netBattery.MaxChargeRate = 1_000;
netBattery.Efficiency = 0.5f;
});
@@ -573,10 +624,13 @@ namespace Content.IntegrationTests.Tests.Power
await server.WaitAssertion(() =>
{
// half a second @ 500 W = 250
// 50% efficiency, so 125 J stored total.
Assert.That(battery.CurrentCharge, Is.EqualTo(125).Within(0.1));
Assert.That(supplier.CurrentSupply, Is.EqualTo(500).Within(0.1));
Assert.Multiple(() =>
{
// half a second @ 500 W = 250
// 50% efficiency, so 125 J stored total.
Assert.That(battery.CurrentCharge, Is.EqualTo(125).Within(0.1));
Assert.That(supplier.CurrentSupply, Is.EqualTo(500).Within(0.1));
});
});
await pairTracker.CleanReturnAsync();
@@ -585,11 +639,16 @@ namespace Content.IntegrationTests.Tests.Power
[Test]
public async Task TestFullBattery()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, ExtraPrototypes = Prototypes});
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
{
NoClient = true,
ExtraPrototypes = Prototypes
});
var server = pairTracker.Pair.Server;
var mapManager = server.ResolveDependency<IMapManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
var gameTiming = server.ResolveDependency<IGameTiming>();
var batterySys = entityManager.System<BatterySystem>();
PowerConsumerComponent consumer = default!;
PowerSupplierComponent supplier = default!;
PowerNetworkBatteryComponent netBattery = default!;
@@ -627,8 +686,8 @@ namespace Content.IntegrationTests.Tests.Power
netBattery.MaxSupply = 400;
netBattery.SupplyRampTolerance = 400;
netBattery.SupplyRampRate = 100_000;
battery.MaxCharge = 100_000;
battery.CurrentCharge = 100_000;
batterySys.SetMaxCharge(batteryEnt, 100_000, battery);
batterySys.SetCharge(batteryEnt, 100_000, battery);
});
// Run some ticks so everything is stable.
@@ -640,16 +699,19 @@ namespace Content.IntegrationTests.Tests.Power
await server.WaitAssertion(() =>
{
Assert.That(consumer.ReceivedPower, Is.EqualTo(consumer.DrawRate).Within(0.1));
Assert.That(supplier.CurrentSupply, Is.EqualTo(supplier.MaxSupply).Within(0.1));
Assert.Multiple(() =>
{
Assert.That(consumer.ReceivedPower, Is.EqualTo(consumer.DrawRate).Within(0.1));
Assert.That(supplier.CurrentSupply, Is.EqualTo(supplier.MaxSupply).Within(0.1));
// Battery's current supply includes passed-through power from the supply.
// Assert ramp position is correct to make sure it's only supplying 200 W for real.
Assert.That(netBattery.CurrentSupply, Is.EqualTo(1000).Within(0.1));
Assert.That(netBattery.SupplyRampPosition, Is.EqualTo(200).Within(0.1));
// Battery's current supply includes passed-through power from the supply.
// Assert ramp position is correct to make sure it's only supplying 200 W for real.
Assert.That(netBattery.CurrentSupply, Is.EqualTo(1000).Within(0.1));
Assert.That(netBattery.SupplyRampPosition, Is.EqualTo(200).Within(0.1));
const int expectedSpent = 200;
Assert.That(battery.CurrentCharge, Is.EqualTo(battery.MaxCharge - expectedSpent).Within(tickDev));
const int expectedSpent = 200;
Assert.That(battery.CurrentCharge, Is.EqualTo(battery.MaxCharge - expectedSpent).Within(tickDev));
});
});
await pairTracker.CleanReturnAsync();
@@ -658,11 +720,16 @@ namespace Content.IntegrationTests.Tests.Power
[Test]
public async Task TestFullBatteryEfficiencyPassThrough()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, ExtraPrototypes = Prototypes});
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
{
NoClient = true,
ExtraPrototypes = Prototypes
});
var server = pairTracker.Pair.Server;
var mapManager = server.ResolveDependency<IMapManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
var gameTiming = server.ResolveDependency<IGameTiming>();
var batterySys = entityManager.System<BatterySystem>();
PowerConsumerComponent consumer = default!;
PowerSupplierComponent supplier = default!;
PowerNetworkBatteryComponent netBattery = default!;
@@ -702,8 +769,8 @@ namespace Content.IntegrationTests.Tests.Power
netBattery.SupplyRampTolerance = 400;
netBattery.SupplyRampRate = 100_000;
netBattery.Efficiency = 0.5f;
battery.MaxCharge = 1_000_000;
battery.CurrentCharge = 1_000_000;
batterySys.SetMaxCharge(batteryEnt, 1_000_000, battery);
batterySys.SetCharge(batteryEnt, 1_000_000, battery);
});
// Run some ticks so everything is stable.
@@ -715,14 +782,17 @@ namespace Content.IntegrationTests.Tests.Power
await server.WaitAssertion(() =>
{
Assert.That(consumer.ReceivedPower, Is.EqualTo(600).Within(0.1));
Assert.That(supplier.CurrentSupply, Is.EqualTo(supplier.MaxSupply).Within(0.1));
Assert.Multiple(() =>
{
Assert.That(consumer.ReceivedPower, Is.EqualTo(600).Within(0.1));
Assert.That(supplier.CurrentSupply, Is.EqualTo(supplier.MaxSupply).Within(0.1));
Assert.That(netBattery.CurrentSupply, Is.EqualTo(600).Within(0.1));
Assert.That(netBattery.SupplyRampPosition, Is.EqualTo(400).Within(0.1));
Assert.That(netBattery.CurrentSupply, Is.EqualTo(600).Within(0.1));
Assert.That(netBattery.SupplyRampPosition, Is.EqualTo(400).Within(0.1));
const int expectedSpent = 400;
Assert.That(battery.CurrentCharge, Is.EqualTo(battery.MaxCharge - expectedSpent).Within(tickDev));
const int expectedSpent = 400;
Assert.That(battery.CurrentCharge, Is.EqualTo(battery.MaxCharge - expectedSpent).Within(tickDev));
});
});
await pairTracker.CleanReturnAsync();
@@ -731,10 +801,15 @@ namespace Content.IntegrationTests.Tests.Power
[Test]
public async Task TestFullBatteryEfficiencyDemandPassThrough()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, ExtraPrototypes = Prototypes});
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
{
NoClient = true,
ExtraPrototypes = Prototypes
});
var server = pairTracker.Pair.Server;
var mapManager = server.ResolveDependency<IMapManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
var batterySys = entityManager.System<BatterySystem>();
PowerConsumerComponent consumer1 = default!;
PowerConsumerComponent consumer2 = default!;
PowerSupplierComponent supplier = default!;
@@ -788,8 +863,8 @@ namespace Content.IntegrationTests.Tests.Power
supplier.MaxSupply = 1000;
supplier.SupplyRampTolerance = 1000;
battery1.MaxCharge = 1_000_000;
battery2.MaxCharge = 1_000_000;
batterySys.SetMaxCharge(batteryEnt1, 1_000_000, battery1);
batterySys.SetMaxCharge(batteryEnt2, 1_000_000, battery2);
netBattery1.MaxChargeRate = 1_000;
netBattery2.MaxChargeRate = 1_000;
@@ -808,9 +883,12 @@ namespace Content.IntegrationTests.Tests.Power
await server.WaitAssertion(() =>
{
Assert.That(consumer1.ReceivedPower, Is.EqualTo(250).Within(0.1));
Assert.That(consumer2.ReceivedPower, Is.EqualTo(500).Within(0.1));
Assert.That(supplier.CurrentSupply, Is.EqualTo(supplier.MaxSupply).Within(0.1));
Assert.Multiple(() =>
{
Assert.That(consumer1.ReceivedPower, Is.EqualTo(250).Within(0.1));
Assert.That(consumer2.ReceivedPower, Is.EqualTo(500).Within(0.1));
Assert.That(supplier.CurrentSupply, Is.EqualTo(supplier.MaxSupply).Within(0.1));
});
});
await pairTracker.CleanReturnAsync();
@@ -828,6 +906,7 @@ namespace Content.IntegrationTests.Tests.Power
var mapManager = server.ResolveDependency<IMapManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
var gameTiming = server.ResolveDependency<IGameTiming>();
var batterySys = entityManager.System<BatterySystem>();
PowerConsumerComponent consumer = default!;
PowerSupplierComponent supplier1 = default!;
PowerSupplierComponent supplier2 = default!;
@@ -887,10 +966,10 @@ namespace Content.IntegrationTests.Tests.Power
netBattery2.SupplyRampTolerance = 1000;
netBattery1.SupplyRampRate = 100_000;
netBattery2.SupplyRampRate = 100_000;
battery1.MaxCharge = 100_000;
battery2.MaxCharge = 100_000;
battery1.CurrentCharge = 100_000;
battery2.CurrentCharge = 100_000;
batterySys.SetMaxCharge(batteryEnt1, 100_000, battery1);
batterySys.SetMaxCharge(batteryEnt2, 100_000, battery2);
batterySys.SetCharge(batteryEnt1, 100_000, battery1);
batterySys.SetCharge(batteryEnt2, 100_000, battery2);
});
// Run some ticks so everything is stable.
@@ -898,14 +977,17 @@ namespace Content.IntegrationTests.Tests.Power
await server.WaitAssertion(() =>
{
Assert.That(consumer.ReceivedPower, Is.EqualTo(consumer.DrawRate).Within(0.1));
Assert.That(supplier1.CurrentSupply, Is.EqualTo(supplier1.MaxSupply).Within(0.1));
Assert.That(supplier2.CurrentSupply, Is.EqualTo(supplier2.MaxSupply).Within(0.1));
Assert.Multiple(() =>
{
Assert.That(consumer.ReceivedPower, Is.EqualTo(consumer.DrawRate).Within(0.1));
Assert.That(supplier1.CurrentSupply, Is.EqualTo(supplier1.MaxSupply).Within(0.1));
Assert.That(supplier2.CurrentSupply, Is.EqualTo(supplier2.MaxSupply).Within(0.1));
Assert.That(netBattery1.CurrentSupply, Is.EqualTo(500).Within(0.1));
Assert.That(netBattery2.CurrentSupply, Is.EqualTo(500).Within(0.1));
Assert.That(netBattery2.SupplyRampPosition, Is.EqualTo(500).Within(0.1));
Assert.That(netBattery2.SupplyRampPosition, Is.EqualTo(500).Within(0.1));
Assert.That(netBattery1.CurrentSupply, Is.EqualTo(500).Within(0.1));
Assert.That(netBattery2.CurrentSupply, Is.EqualTo(500).Within(0.1));
Assert.That(netBattery2.SupplyRampPosition, Is.EqualTo(500).Within(0.1));
Assert.That(netBattery2.SupplyRampPosition, Is.EqualTo(500).Within(0.1));
});
});
await pairTracker.CleanReturnAsync();
@@ -917,10 +999,15 @@ namespace Content.IntegrationTests.Tests.Power
[Test]
public async Task TestBatteriesProportional()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, ExtraPrototypes = Prototypes});
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
{
NoClient = true,
ExtraPrototypes = Prototypes
});
var server = pairTracker.Pair.Server;
var mapManager = server.ResolveDependency<IMapManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
var batterySys = entityManager.System<BatterySystem>();
PowerConsumerComponent consumer1 = default!;
PowerConsumerComponent consumer2 = default!;
PowerSupplierComponent supplier = default!;
@@ -968,8 +1055,8 @@ namespace Content.IntegrationTests.Tests.Power
supplier.MaxSupply = 1000;
supplier.SupplyRampTolerance = 1000;
battery1.MaxCharge = 1_000_000;
battery2.MaxCharge = 1_000_000;
batterySys.SetMaxCharge(batteryEnt1, 1_000_000, battery1);
batterySys.SetMaxCharge(batteryEnt2, 1_000_000, battery2);
netBattery1.MaxChargeRate = 20;
netBattery2.MaxChargeRate = 20;
@@ -986,12 +1073,15 @@ namespace Content.IntegrationTests.Tests.Power
await server.WaitAssertion(() =>
{
// NOTE: MaxChargeRate on batteries actually skews the demand.
// So that's why the tolerance is so high, the charge rate is so *low*,
// and we run so many ticks to stabilize.
Assert.That(consumer1.ReceivedPower, Is.EqualTo(333.333).Within(10));
Assert.That(consumer2.ReceivedPower, Is.EqualTo(666.666).Within(10));
Assert.That(supplier.CurrentSupply, Is.EqualTo(supplier.MaxSupply).Within(0.1));
Assert.Multiple(() =>
{
// NOTE: MaxChargeRate on batteries actually skews the demand.
// So that's why the tolerance is so high, the charge rate is so *low*,
// and we run so many ticks to stabilize.
Assert.That(consumer1.ReceivedPower, Is.EqualTo(333.333).Within(10));
Assert.That(consumer2.ReceivedPower, Is.EqualTo(666.666).Within(10));
Assert.That(supplier.CurrentSupply, Is.EqualTo(supplier.MaxSupply).Within(0.1));
});
});
await pairTracker.CleanReturnAsync();
@@ -1000,10 +1090,15 @@ namespace Content.IntegrationTests.Tests.Power
[Test]
public async Task TestBatteryEngineCut()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, ExtraPrototypes = Prototypes});
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
{
NoClient = true,
ExtraPrototypes = Prototypes
});
var server = pairTracker.Pair.Server;
var mapManager = server.ResolveDependency<IMapManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
var batterySys = entityManager.System<BatterySystem>();
PowerConsumerComponent consumer = default!;
PowerSupplierComponent supplier = default!;
PowerNetworkBatteryComponent netBattery = default!;
@@ -1039,8 +1134,8 @@ namespace Content.IntegrationTests.Tests.Power
netBattery.MaxSupply = 1000;
netBattery.SupplyRampTolerance = 200;
netBattery.SupplyRampRate = 10;
battery.MaxCharge = 100_000;
battery.CurrentCharge = 100_000;
batterySys.SetMaxCharge(batteryEnt, 100_000, battery);
batterySys.SetCharge(batteryEnt, 100_000, battery);
});
// Run some ticks so everything is stable.
@@ -1048,9 +1143,12 @@ namespace Content.IntegrationTests.Tests.Power
await server.WaitAssertion(() =>
{
// Supply and consumer are fully loaded/supplied.
Assert.That(consumer.ReceivedPower, Is.EqualTo(consumer.DrawRate).Within(0.5));
Assert.That(supplier.CurrentSupply, Is.EqualTo(supplier.MaxSupply).Within(0.5));
Assert.Multiple(() =>
{
// Supply and consumer are fully loaded/supplied.
Assert.That(consumer.ReceivedPower, Is.EqualTo(consumer.DrawRate).Within(0.5));
Assert.That(supplier.CurrentSupply, Is.EqualTo(supplier.MaxSupply).Within(0.5));
});
// Cut off the supplier
supplier.Enabled = false;
@@ -1062,10 +1160,13 @@ namespace Content.IntegrationTests.Tests.Power
await server.WaitAssertion(() =>
{
// Assert that network drops to 0 power and starts ramping up
Assert.That(consumer.ReceivedPower, Is.LessThan(50).And.GreaterThan(0));
Assert.That(netBattery.CurrentReceiving, Is.EqualTo(0));
Assert.That(netBattery.CurrentSupply, Is.GreaterThan(0));
Assert.Multiple(() =>
{
// Assert that network drops to 0 power and starts ramping up
Assert.That(consumer.ReceivedPower, Is.LessThan(50).And.GreaterThan(0));
Assert.That(netBattery.CurrentReceiving, Is.EqualTo(0));
Assert.That(netBattery.CurrentSupply, Is.GreaterThan(0));
});
});
await pairTracker.CleanReturnAsync();
@@ -1077,11 +1178,15 @@ namespace Content.IntegrationTests.Tests.Power
[Test]
public async Task TestTerminalNodeGroups()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, ExtraPrototypes = Prototypes});
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
{
NoClient = true,
ExtraPrototypes = Prototypes
});
var server = pairTracker.Pair.Server;
var mapManager = server.ResolveDependency<IMapManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
var _nodeContainer = entityManager.System<NodeContainerSystem>();
var nodeContainer = entityManager.System<NodeContainerSystem>();
CableNode leftNode = default!;
CableNode rightNode = default!;
Node batteryInput = default!;
@@ -1109,16 +1214,16 @@ namespace Content.IntegrationTests.Tests.Power
var battery = entityManager.SpawnEntity("FullBatteryDummy", grid.ToCoordinates(0, 2));
var batteryNodeContainer = entityManager.GetComponent<NodeContainerComponent>(battery);
if (_nodeContainer.TryGetNode<CableNode>(entityManager.GetComponent<NodeContainerComponent>(leftEnt),
if (nodeContainer.TryGetNode<CableNode>(entityManager.GetComponent<NodeContainerComponent>(leftEnt),
"power", out var leftN))
leftNode = leftN;
if (_nodeContainer.TryGetNode<CableNode>(entityManager.GetComponent<NodeContainerComponent>(rightEnt),
if (nodeContainer.TryGetNode<CableNode>(entityManager.GetComponent<NodeContainerComponent>(rightEnt),
"power", out var rightN))
rightNode = rightN;
if (_nodeContainer.TryGetNode<Node>(batteryNodeContainer, "input", out var nInput))
if (nodeContainer.TryGetNode<Node>(batteryNodeContainer, "input", out var nInput))
batteryInput = nInput;
if (_nodeContainer.TryGetNode<Node>(batteryNodeContainer, "output", out var nOutput))
if (nodeContainer.TryGetNode<Node>(batteryNodeContainer, "output", out var nOutput))
batteryOutput = nOutput;
});
@@ -1127,10 +1232,13 @@ namespace Content.IntegrationTests.Tests.Power
await server.WaitAssertion(() =>
{
Assert.That(batteryInput.NodeGroup, Is.EqualTo(leftNode.NodeGroup));
Assert.That(batteryOutput.NodeGroup, Is.EqualTo(rightNode.NodeGroup));
Assert.Multiple(() =>
{
Assert.That(batteryInput.NodeGroup, Is.EqualTo(leftNode.NodeGroup));
Assert.That(batteryOutput.NodeGroup, Is.EqualTo(rightNode.NodeGroup));
Assert.That(leftNode.NodeGroup, Is.Not.EqualTo(rightNode.NodeGroup));
Assert.That(leftNode.NodeGroup, Is.Not.EqualTo(rightNode.NodeGroup));
});
});
await pairTracker.CleanReturnAsync();
@@ -1139,10 +1247,15 @@ namespace Content.IntegrationTests.Tests.Power
[Test]
public async Task ApcChargingTest()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, ExtraPrototypes = Prototypes});
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
{
NoClient = true,
ExtraPrototypes = Prototypes
});
var server = pairTracker.Pair.Server;
var mapManager = server.ResolveDependency<IMapManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
var batterySys = entityManager.System<BatterySystem>();
PowerNetworkBatteryComponent substationNetBattery = default!;
BatteryComponent apcBattery = default!;
@@ -1173,15 +1286,18 @@ namespace Content.IntegrationTests.Tests.Power
generatorSupplier.MaxSupply = 1000;
generatorSupplier.SupplyRampTolerance = 1000;
apcBattery.CurrentCharge = 0;
batterySys.SetCharge(apcEnt, 0, apcBattery);
});
server.RunTicks(5); //let run a few ticks for PowerNets to reevaluate and start charging apc
await server.WaitAssertion(() =>
{
Assert.That(substationNetBattery.CurrentSupply, Is.GreaterThan(0)); //substation should be providing power
Assert.That(apcBattery.CurrentCharge, Is.GreaterThan(0)); //apc battery should have gained charge
Assert.Multiple(() =>
{
Assert.That(substationNetBattery.CurrentSupply, Is.GreaterThan(0)); //substation should be providing power
Assert.That(apcBattery.CurrentCharge, Is.GreaterThan(0)); //apc battery should have gained charge
});
});
await pairTracker.CleanReturnAsync();
@@ -1190,11 +1306,16 @@ namespace Content.IntegrationTests.Tests.Power
[Test]
public async Task ApcNetTest()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, ExtraPrototypes = Prototypes});
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
{
NoClient = true,
ExtraPrototypes = Prototypes
});
var server = pairTracker.Pair.Server;
var mapManager = server.ResolveDependency<IMapManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
var extensionCableSystem = entityManager.EntitySysManager.GetEntitySystem<ExtensionCableSystem>();
var batterySys = entityManager.System<BatterySystem>();
var extensionCableSystem = entityManager.System<ExtensionCableSystem>();
PowerNetworkBatteryComponent apcNetBattery = default!;
ApcPowerReceiverComponent receiver = default!;
ApcPowerReceiverComponent unpoweredReceiver = default!;
@@ -1229,15 +1350,16 @@ namespace Content.IntegrationTests.Tests.Power
extensionCableSystem.SetProviderTransferRange(apcExtensionEnt, range);
extensionCableSystem.SetReceiverReceptionRange(powerReceiverEnt, range);
battery.MaxCharge = 10000; //arbitrary nonzero amount of charge
battery.CurrentCharge = battery.MaxCharge; //fill battery
batterySys.SetMaxCharge(apcEnt, 10000, battery); //arbitrary nonzero amount of charge
batterySys.SetCharge(apcEnt, battery.MaxCharge, battery); //fill battery
receiver.Load = 1; //arbitrary small amount of power
});
server.RunTicks(1); //let run a tick for ApcNet to process power
await server.WaitAssertion(() => {
await server.WaitAssertion(() =>
{
Assert.Multiple(() =>
{
Assert.That(receiver.Powered, "Receiver in range should be powered");